Skip to content

Commit f530819

Browse files
committed
Merge branch '2.4.x' into 2.5.x
Closes gh-27966
2 parents 2004c06 + 273600b commit f530819

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed
Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,19 +19,15 @@
1919
import org.gradle.api.Plugin;
2020
import org.gradle.api.Project;
2121
import org.gradle.api.artifacts.Configuration;
22-
import org.gradle.api.attributes.Usage;
2322
import org.gradle.api.plugins.JavaPlugin;
2423
import org.gradle.api.plugins.JavaPluginConvention;
2524
import org.gradle.api.tasks.SourceSetContainer;
26-
import org.gradle.api.tasks.javadoc.Javadoc;
27-
import org.gradle.plugins.ide.eclipse.EclipsePlugin;
28-
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
2925

3026
/**
3127
* A {@code Plugin} that adds support for Maven-style optional dependencies. Creates a new
3228
* {@code optional} configuration. The {@code optional} configuration is part of the
33-
* project's compile and runtime classpath's but does not affect the classpath of
34-
* dependent projects.
29+
* project's compile and runtime classpaths but does not affect the classpath of dependent
30+
* projects.
3531
*
3632
* @author Andy Wilkinson
3733
*/
@@ -44,22 +40,19 @@ public class OptionalDependenciesPlugin implements Plugin<Project> {
4440

4541
@Override
4642
public void apply(Project project) {
47-
Configuration optional = project.getConfigurations().create(OPTIONAL_CONFIGURATION_NAME);
48-
optional.attributes((attributes) -> attributes.attribute(Usage.USAGE_ATTRIBUTE,
49-
project.getObjects().named(Usage.class, Usage.JAVA_RUNTIME)));
43+
Configuration optional = project.getConfigurations().create("optional");
44+
optional.setCanBeConsumed(false);
45+
optional.setCanBeResolved(false);
5046
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> {
5147
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class)
5248
.getSourceSets();
5349
sourceSets.all((sourceSet) -> {
54-
sourceSet.setCompileClasspath(sourceSet.getCompileClasspath().plus(optional));
55-
sourceSet.setRuntimeClasspath(sourceSet.getRuntimeClasspath().plus(optional));
50+
project.getConfigurations().getByName(sourceSet.getCompileClasspathConfigurationName())
51+
.extendsFrom(optional);
52+
project.getConfigurations().getByName(sourceSet.getRuntimeClasspathConfigurationName())
53+
.extendsFrom(optional);
5654
});
57-
project.getTasks().withType(Javadoc.class)
58-
.all((javadoc) -> javadoc.setClasspath(javadoc.getClasspath().plus(optional)));
5955
});
60-
project.getPlugins().withType(EclipsePlugin.class,
61-
(eclipsePlugin) -> project.getExtensions().getByType(EclipseModel.class)
62-
.classpath((classpath) -> classpath.getPlusConfigurations().add(optional)));
6356
}
6457

6558
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
import org.gradle.testkit.runner.BuildResult;
4545
import org.gradle.testkit.runner.GradleRunner;
4646
import org.gradle.util.GradleVersion;
47-
import org.jetbrains.kotlin.cli.common.PropertiesKt;
48-
import org.jetbrains.kotlin.compilerRunner.KotlinLogger;
49-
import org.jetbrains.kotlin.daemon.client.KotlinCompilerClient;
5047
import org.jetbrains.kotlin.gradle.model.KotlinProject;
5148
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin;
5249
import org.jetbrains.kotlin.gradle.plugin.KotlinPlugin;
@@ -110,9 +107,10 @@ private List<File> pluginClasspath() {
110107
new File("build/resources/main"), new File(pathOfJarContaining(LaunchScript.class)),
111108
new File(pathOfJarContaining(ClassVisitor.class)),
112109
new File(pathOfJarContaining(DependencyManagementPlugin.class)),
113-
new File(pathOfJarContaining(PropertiesKt.class)), new File(pathOfJarContaining(KotlinLogger.class)),
110+
new File(pathOfJarContaining("org.jetbrains.kotlin.cli.common.PropertiesKt")),
111+
new File(pathOfJarContaining("org.jetbrains.kotlin.compilerRunner.KotlinLogger")),
114112
new File(pathOfJarContaining(KotlinPlugin.class)), new File(pathOfJarContaining(KotlinProject.class)),
115-
new File(pathOfJarContaining(KotlinCompilerClient.class)),
113+
new File(pathOfJarContaining("org.jetbrains.kotlin.daemon.client.KotlinCompilerClient")),
116114
new File(pathOfJarContaining(KotlinCompilerPluginSupportPlugin.class)),
117115
new File(pathOfJarContaining(LanguageSettings.class)),
118116
new File(pathOfJarContaining(ArchiveEntry.class)), new File(pathOfJarContaining(BuildRequest.class)),
@@ -124,6 +122,15 @@ private List<File> pluginClasspath() {
124122
new File(pathOfJarContaining(Toml.class)), new File(pathOfJarContaining(Lexer.class)));
125123
}
126124

125+
private String pathOfJarContaining(String className) {
126+
try {
127+
return pathOfJarContaining(Class.forName(className));
128+
}
129+
catch (ClassNotFoundException ex) {
130+
throw new IllegalArgumentException(ex);
131+
}
132+
}
133+
127134
private String pathOfJarContaining(Class<?> type) {
128135
return type.getProtectionDomain().getCodeSource().getLocation().getPath();
129136
}

0 commit comments

Comments
 (0)