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
This commit is contained in:
Brian Clozel 2019-08-13 17:51:13 +02:00
parent eff9cae314
commit 561af5f8f9
9 changed files with 77 additions and 11 deletions

View File

@ -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"

View File

@ -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"

View File

@ -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<Project> {
/**
* 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);
});
});
}
}

View File

@ -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<Project> {
JavaPlugin.COMPILE_CONFIGURATION_NAME,
JavaPlugin.API_CONFIGURATION_NAME,
JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME,
"optional",
OptionalDependenciesPlugin.OPTIONAL_CONFIGURATION_NAME,
JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME);
@Override

View File

@ -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

View File

@ -1,4 +1,4 @@
apply plugin: "propdeps-maven"
apply plugin: "maven"
install {
repositories.mavenInstaller {

View File

@ -20,5 +20,3 @@ eclipse {
containers "org.jetbrains.kotlin.core.KOTLIN_CONTAINER"
}
}
configurations.archives.artifacts.clear()

View File

@ -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")
}

View File

@ -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")