Skip to content

Commit 561af5f

Browse files
committed
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
1 parent eff9cae commit 561af5f

File tree

9 files changed

+77
-11
lines changed

9 files changed

+77
-11
lines changed

build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ buildscript {
33
maven { url "https://repo.spring.io/plugins-release" }
44
}
55
dependencies {
6-
classpath("io.spring.gradle:propdeps-plugin:0.0.9.RELEASE")
76
classpath("io.spring.nohttp:nohttp-gradle:0.0.3.RELEASE")
87
classpath("org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16")
98
classpath("io.spring.asciidoctor:spring-asciidoctor-extensions:0.1.3.RELEASE")
@@ -65,7 +64,7 @@ configure(allprojects) { project ->
6564
apply plugin: "java"
6665
apply plugin: "kotlin"
6766
apply plugin: "checkstyle"
68-
apply plugin: "propdeps"
67+
apply plugin: 'org.springframework.build.optional-dependencies'
6968
apply plugin: 'org.springframework.build.test-sources'
7069
apply plugin: "io.spring.dependency-management"
7170
apply from: "${gradleScriptDir}/ide.gradle"

buildSrc/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ dependencies {
1313

1414
gradlePlugin {
1515
plugins {
16+
optionalDependenciesPlugin {
17+
id = "org.springframework.build.optional-dependencies"
18+
implementationClass = "org.springframework.build.optional.OptionalDependenciesPlugin"
19+
}
1620
testSourcesPlugin {
1721
id = "org.springframework.build.test-sources"
1822
implementationClass = "org.springframework.build.testsources.TestSourcesPlugin"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2002-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.build.optional;
18+
19+
import org.gradle.api.Plugin;
20+
import org.gradle.api.Project;
21+
import org.gradle.api.artifacts.Configuration;
22+
import org.gradle.api.plugins.JavaPlugin;
23+
import org.gradle.api.plugins.JavaPluginConvention;
24+
import org.gradle.api.tasks.SourceSetContainer;
25+
import org.gradle.plugins.ide.eclipse.EclipsePlugin;
26+
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
27+
28+
/**
29+
* A {@code Plugin} that adds support for Maven-style optional dependencies. Creates a new
30+
* {@code optional} configuration. The {@code optional} configuration is part of the
31+
* project's compile and runtime classpath's but does not affect the classpath of
32+
* dependent projects.
33+
*
34+
* @author Andy Wilkinson
35+
*/
36+
public class OptionalDependenciesPlugin implements Plugin<Project> {
37+
38+
/**
39+
* Name of the {@code optional} configuration.
40+
*/
41+
public static final String OPTIONAL_CONFIGURATION_NAME = "optional";
42+
43+
@Override
44+
public void apply(Project project) {
45+
Configuration optional = project.getConfigurations().create("optional");
46+
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> {
47+
SourceSetContainer sourceSets = project.getConvention()
48+
.getPlugin(JavaPluginConvention.class).getSourceSets();
49+
sourceSets.all((sourceSet) -> {
50+
sourceSet.setCompileClasspath(
51+
sourceSet.getCompileClasspath().plus(optional));
52+
sourceSet.setRuntimeClasspath(
53+
sourceSet.getRuntimeClasspath().plus(optional));
54+
});
55+
});
56+
project.getPlugins().withType(EclipsePlugin.class, (eclipePlugin) -> {
57+
project.getExtensions().getByType(EclipseModel.class)
58+
.classpath((classpath) -> {
59+
classpath.getPlusConfigurations().add(optional);
60+
});
61+
});
62+
}
63+
64+
}

buildSrc/src/main/java/org/springframework/build/testsources/TestSourcesPlugin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.gradle.api.tasks.SourceSet;
3131
import org.gradle.api.tasks.SourceSetOutput;
3232

33+
import org.springframework.build.optional.OptionalDependenciesPlugin;
34+
3335
/**
3436
* {@link Plugin} that automatically updates testCompile dependencies to include
3537
* the test source sets of {@code project()} dependencies.
@@ -49,7 +51,7 @@ public class TestSourcesPlugin implements Plugin<Project> {
4951
JavaPlugin.COMPILE_CONFIGURATION_NAME,
5052
JavaPlugin.API_CONFIGURATION_NAME,
5153
JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME,
52-
"optional",
54+
OptionalDependenciesPlugin.OPTIONAL_CONFIGURATION_NAME,
5355
JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME);
5456

5557
@Override

gradle/ide.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
22
import org.gradle.plugins.ide.eclipse.model.SourceFolder
33

4-
5-
apply plugin: "propdeps-eclipse"
6-
apply plugin: "propdeps-idea"
4+
apply plugin: "eclipse"
75

86
eclipse.jdt {
97
sourceCompatibility = 1.8

gradle/publish-maven.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apply plugin: "propdeps-maven"
1+
apply plugin: "maven"
22

33
install {
44
repositories.mavenInstaller {

spring-core-coroutines/spring-core-coroutines.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,3 @@ eclipse {
2020
containers "org.jetbrains.kotlin.core.KOTLIN_CONTAINER"
2121
}
2222
}
23-
24-
configurations.archives.artifacts.clear()

spring-jms/spring-jms.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
description = "Spring JMS"
22

33
dependencies {
4-
provided("javax.jms:javax.jms-api:2.0.1")
54
compile(project(":spring-beans"))
65
compile(project(":spring-core"))
76
compile(project(":spring-messaging"))
87
compile(project(":spring-tx"))
8+
compileOnly("javax.jms:javax.jms-api:2.0.1")
99
optional(project(":spring-aop"))
1010
optional(project(":spring-context"))
1111
optional(project(":spring-oxm"))
1212
optional("javax.resource:javax.resource-api:1.7.1")
1313
optional("javax.transaction:javax.transaction-api:1.3")
1414
optional("com.fasterxml.jackson.core:jackson-databind:${jackson2Version}")
15+
testCompileOnly("javax.jms:javax.jms-api:2.0.1")
1516
}

spring-webmvc/spring-webmvc.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ dependencyManagement {
88
}
99

1010
dependencies {
11-
provided("javax.servlet:javax.servlet-api:4.0.1")
1211
compile(project(":spring-aop"))
1312
compile(project(":spring-beans"))
1413
compile(project(":spring-context"))
1514
compile(project(":spring-core"))
1615
compile(project(":spring-expression"))
1716
compile(project(":spring-web"))
17+
compileOnly("javax.servlet:javax.servlet-api:4.0.1")
1818
optional(project(":spring-context-support")) // for FreeMarker support
1919
optional(project(":spring-oxm"))
2020
optional("javax.servlet.jsp:javax.servlet.jsp-api:2.3.2-b02")

0 commit comments

Comments
 (0)