From 561af5f8f936ed4608fff67e0af2a5872031df24 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 13 Aug 2019 17:51:13 +0200 Subject: [PATCH] Replace propdeps plugin with custom plugin Prior to this commit, the Spring Framework build would be using the propdeps Gradle plugin to introduce two new configurations to the build: "optional" and "provided". This would also configure related conventions for IDEs, adding those configurations to published POMs. This commit removes the need for this plugin and creates instead a custom plugin for an "optional" configuration. While the Eclipse IDE support is still supported, there is no need for specific conventions for IntelliJ IDEA anymore. This new plugin does not introduce the "provided" scope, as "compileOnly" and "testCompileOnly" are here for that. Also as of this commit, optional/provided dependencies are not published with the Spring Framework modules POMs annymore. Generally, these dependencies do not provide actionable information to the developers reading / tools consuming the published POMs. Optional/Provided dependencies are **not**: * dependencies you can add to enable some supported feature * dependencies versions that you can use to figure out CVEs or bugs * dependencies that might be missing in existing Spring applications In the context of Spring Framework, optional dependencies are just libraries are Spring is compiling against for various technical reasons. With that in mind, we are not publishing that information anymore. See gh-23282 --- build.gradle | 3 +- buildSrc/build.gradle | 4 ++ .../optional/OptionalDependenciesPlugin.java | 64 +++++++++++++++++++ .../build/testsources/TestSourcesPlugin.java | 4 +- gradle/ide.gradle | 4 +- gradle/publish-maven.gradle | 2 +- .../spring-core-coroutines.gradle | 2 - spring-jms/spring-jms.gradle | 3 +- spring-webmvc/spring-webmvc.gradle | 2 +- 9 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 buildSrc/src/main/java/org/springframework/build/optional/OptionalDependenciesPlugin.java diff --git a/build.gradle b/build.gradle index c7c858ed610..8aaa2f3ded5 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,6 @@ buildscript { maven { url "https://repo.spring.io/plugins-release" } } dependencies { - classpath("io.spring.gradle:propdeps-plugin:0.0.9.RELEASE") classpath("io.spring.nohttp:nohttp-gradle:0.0.3.RELEASE") classpath("org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16") classpath("io.spring.asciidoctor:spring-asciidoctor-extensions:0.1.3.RELEASE") @@ -65,7 +64,7 @@ configure(allprojects) { project -> apply plugin: "java" apply plugin: "kotlin" apply plugin: "checkstyle" - apply plugin: "propdeps" + apply plugin: 'org.springframework.build.optional-dependencies' apply plugin: 'org.springframework.build.test-sources' apply plugin: "io.spring.dependency-management" apply from: "${gradleScriptDir}/ide.gradle" diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index ede6eabd82d..3b1c253c0cc 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -13,6 +13,10 @@ dependencies { gradlePlugin { plugins { + optionalDependenciesPlugin { + id = "org.springframework.build.optional-dependencies" + implementationClass = "org.springframework.build.optional.OptionalDependenciesPlugin" + } testSourcesPlugin { id = "org.springframework.build.test-sources" implementationClass = "org.springframework.build.testsources.TestSourcesPlugin" diff --git a/buildSrc/src/main/java/org/springframework/build/optional/OptionalDependenciesPlugin.java b/buildSrc/src/main/java/org/springframework/build/optional/OptionalDependenciesPlugin.java new file mode 100644 index 00000000000..55537c2d825 --- /dev/null +++ b/buildSrc/src/main/java/org/springframework/build/optional/OptionalDependenciesPlugin.java @@ -0,0 +1,64 @@ +/* + * Copyright 2002-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.build.optional; + +import org.gradle.api.Plugin; +import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.plugins.JavaPlugin; +import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.tasks.SourceSetContainer; +import org.gradle.plugins.ide.eclipse.EclipsePlugin; +import org.gradle.plugins.ide.eclipse.model.EclipseModel; + +/** + * A {@code Plugin} that adds support for Maven-style optional dependencies. Creates a new + * {@code optional} configuration. The {@code optional} configuration is part of the + * project's compile and runtime classpath's but does not affect the classpath of + * dependent projects. + * + * @author Andy Wilkinson + */ +public class OptionalDependenciesPlugin implements Plugin { + + /** + * Name of the {@code optional} configuration. + */ + public static final String OPTIONAL_CONFIGURATION_NAME = "optional"; + + @Override + public void apply(Project project) { + Configuration optional = project.getConfigurations().create("optional"); + project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> { + SourceSetContainer sourceSets = project.getConvention() + .getPlugin(JavaPluginConvention.class).getSourceSets(); + sourceSets.all((sourceSet) -> { + sourceSet.setCompileClasspath( + sourceSet.getCompileClasspath().plus(optional)); + sourceSet.setRuntimeClasspath( + sourceSet.getRuntimeClasspath().plus(optional)); + }); + }); + project.getPlugins().withType(EclipsePlugin.class, (eclipePlugin) -> { + project.getExtensions().getByType(EclipseModel.class) + .classpath((classpath) -> { + classpath.getPlusConfigurations().add(optional); + }); + }); + } + +} \ No newline at end of file diff --git a/buildSrc/src/main/java/org/springframework/build/testsources/TestSourcesPlugin.java b/buildSrc/src/main/java/org/springframework/build/testsources/TestSourcesPlugin.java index 5bdf4d0e630..fd907586bef 100644 --- a/buildSrc/src/main/java/org/springframework/build/testsources/TestSourcesPlugin.java +++ b/buildSrc/src/main/java/org/springframework/build/testsources/TestSourcesPlugin.java @@ -30,6 +30,8 @@ import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSetOutput; +import org.springframework.build.optional.OptionalDependenciesPlugin; + /** * {@link Plugin} that automatically updates testCompile dependencies to include * the test source sets of {@code project()} dependencies. @@ -49,7 +51,7 @@ public class TestSourcesPlugin implements Plugin { JavaPlugin.COMPILE_CONFIGURATION_NAME, JavaPlugin.API_CONFIGURATION_NAME, JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, - "optional", + OptionalDependenciesPlugin.OPTIONAL_CONFIGURATION_NAME, JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME); @Override diff --git a/gradle/ide.gradle b/gradle/ide.gradle index 85fe8b4cf7f..554d4b3c543 100644 --- a/gradle/ide.gradle +++ b/gradle/ide.gradle @@ -1,9 +1,7 @@ import org.gradle.plugins.ide.eclipse.model.ProjectDependency import org.gradle.plugins.ide.eclipse.model.SourceFolder - -apply plugin: "propdeps-eclipse" -apply plugin: "propdeps-idea" +apply plugin: "eclipse" eclipse.jdt { sourceCompatibility = 1.8 diff --git a/gradle/publish-maven.gradle b/gradle/publish-maven.gradle index dad95c8452f..eb429bb57ec 100644 --- a/gradle/publish-maven.gradle +++ b/gradle/publish-maven.gradle @@ -1,4 +1,4 @@ -apply plugin: "propdeps-maven" +apply plugin: "maven" install { repositories.mavenInstaller { diff --git a/spring-core-coroutines/spring-core-coroutines.gradle b/spring-core-coroutines/spring-core-coroutines.gradle index 94feb49b964..7a8747c381b 100644 --- a/spring-core-coroutines/spring-core-coroutines.gradle +++ b/spring-core-coroutines/spring-core-coroutines.gradle @@ -20,5 +20,3 @@ eclipse { containers "org.jetbrains.kotlin.core.KOTLIN_CONTAINER" } } - -configurations.archives.artifacts.clear() diff --git a/spring-jms/spring-jms.gradle b/spring-jms/spring-jms.gradle index 84ec0de5e3e..f48cf58a54f 100644 --- a/spring-jms/spring-jms.gradle +++ b/spring-jms/spring-jms.gradle @@ -1,15 +1,16 @@ description = "Spring JMS" dependencies { - provided("javax.jms:javax.jms-api:2.0.1") compile(project(":spring-beans")) compile(project(":spring-core")) compile(project(":spring-messaging")) compile(project(":spring-tx")) + compileOnly("javax.jms:javax.jms-api:2.0.1") optional(project(":spring-aop")) optional(project(":spring-context")) optional(project(":spring-oxm")) optional("javax.resource:javax.resource-api:1.7.1") optional("javax.transaction:javax.transaction-api:1.3") optional("com.fasterxml.jackson.core:jackson-databind:${jackson2Version}") + testCompileOnly("javax.jms:javax.jms-api:2.0.1") } diff --git a/spring-webmvc/spring-webmvc.gradle b/spring-webmvc/spring-webmvc.gradle index 4a93e510651..8ca041483fb 100644 --- a/spring-webmvc/spring-webmvc.gradle +++ b/spring-webmvc/spring-webmvc.gradle @@ -8,13 +8,13 @@ dependencyManagement { } dependencies { - provided("javax.servlet:javax.servlet-api:4.0.1") compile(project(":spring-aop")) compile(project(":spring-beans")) compile(project(":spring-context")) compile(project(":spring-core")) compile(project(":spring-expression")) compile(project(":spring-web")) + compileOnly("javax.servlet:javax.servlet-api:4.0.1") optional(project(":spring-context-support")) // for FreeMarker support optional(project(":spring-oxm")) optional("javax.servlet.jsp:javax.servlet.jsp-api:2.3.2-b02")