Skip to content

Commit 714a187

Browse files
committed
Rework dep mgmt again to avoid consumers picking up strict constraints
This paves the way for publishing Gradle module metadata once the problem caused by snapshot versions and our two-step publication process has been addressed. See gh-19609
1 parent 5ba0a91 commit 714a187

File tree

79 files changed

+212
-106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+212
-106
lines changed

buildSrc/build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ gradlePlugin {
5353
id = "org.springframework.boot.conventions"
5454
implementationClass = "org.springframework.boot.build.ConventionsPlugin"
5555
}
56+
dependencyManagementPlugin {
57+
id = "org.springframework.boot.internal-dependency-management"
58+
implementationClass = "org.springframework.boot.build.InternalDependencyManagementPlugin"
59+
}
5660
deployedPlugin {
5761
id = "org.springframework.boot.deployed"
5862
implementationClass = "org.springframework.boot.build.DeployedPlugin"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2020-2020 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.boot.build;
18+
19+
import java.util.Collections;
20+
21+
import org.gradle.api.Plugin;
22+
import org.gradle.api.Project;
23+
import org.gradle.api.artifacts.Configuration;
24+
import org.gradle.api.artifacts.ConfigurationContainer;
25+
import org.gradle.api.artifacts.Dependency;
26+
import org.gradle.api.plugins.JavaBasePlugin;
27+
28+
import org.springframework.boot.build.optional.OptionalDependenciesPlugin;
29+
30+
/**
31+
* Plugin to apply internal dependency management to Spring Boot's projects. Uses a custom
32+
* configuration to enforce a platform for Spring Boot's own build. This prevents the
33+
* enforced (strict) constraints from being visible to external consumers.
34+
*
35+
* @author Andy Wilkinson
36+
*/
37+
public class InternalDependencyManagementPlugin implements Plugin<Project> {
38+
39+
@Override
40+
public void apply(Project project) {
41+
project.getPlugins().withType(JavaBasePlugin.class, (java) -> configureDependencyManagement(project));
42+
}
43+
44+
private void configureDependencyManagement(Project project) {
45+
ConfigurationContainer configurations = project.getConfigurations();
46+
Configuration dependencyManagement = configurations.create("internalDependencyManagement", (configuration) -> {
47+
configuration.setVisible(false);
48+
configuration.setCanBeConsumed(false);
49+
configuration.setCanBeResolved(false);
50+
});
51+
configurations.matching((configuration) -> configuration.getName().endsWith("Classpath"))
52+
.all((configuration) -> configuration.extendsFrom(dependencyManagement));
53+
Dependency springBootParent = project.getDependencies().enforcedPlatform(project.getDependencies()
54+
.project(Collections.singletonMap("path", ":spring-boot-project:spring-boot-parent")));
55+
dependencyManagement.getDependencies().add(springBootParent);
56+
project.getPlugins().withType(OptionalDependenciesPlugin.class, (optionalDependencies) -> configurations
57+
.getByName(OptionalDependenciesPlugin.OPTIONAL_CONFIGURATION_NAME).extendsFrom(dependencyManagement));
58+
}
59+
60+
}

buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.gradle.api.InvalidUserCodeException;
3131
import org.gradle.api.InvalidUserDataException;
3232
import org.gradle.api.artifacts.dsl.DependencyHandler;
33+
import org.gradle.api.plugins.JavaPlatformPlugin;
3334
import org.gradle.util.ConfigureUtil;
3435

3536
import org.springframework.boot.build.bom.Library.Exclusion;
@@ -51,10 +52,10 @@ public class BomExtension {
5152

5253
private final List<Library> libraries = new ArrayList<Library>();
5354

54-
private final DependencyHandler dependencyHandler;
55-
5655
private final UpgradeHandler upgradeHandler = new UpgradeHandler();
5756

57+
private final DependencyHandler dependencyHandler;
58+
5859
public BomExtension(DependencyHandler dependencyHandler) {
5960
this.dependencyHandler = dependencyHandler;
6061
}
@@ -107,13 +108,16 @@ private void addLibrary(Library library) {
107108
for (Group group : library.getGroups()) {
108109
for (Module module : group.getModules()) {
109110
this.putArtifactVersionProperty(group.getId(), module.getName(), library.getVersionProperty());
110-
this.dependencyHandler.getConstraints().add("api",
111+
this.dependencyHandler.getConstraints().add(JavaPlatformPlugin.API_CONFIGURATION_NAME,
111112
createDependencyNotation(group.getId(), module.getName(), library.getVersion()));
112113
}
113114
for (String bomImport : group.getBoms()) {
114115
this.putArtifactVersionProperty(group.getId(), bomImport, library.getVersionProperty());
115-
this.dependencyHandler.add("api", this.dependencyHandler
116-
.enforcedPlatform(createDependencyNotation(group.getId(), bomImport, library.getVersion())));
116+
String bomDependency = createDependencyNotation(group.getId(), bomImport, library.getVersion());
117+
this.dependencyHandler.add(JavaPlatformPlugin.API_CONFIGURATION_NAME,
118+
this.dependencyHandler.platform(bomDependency));
119+
this.dependencyHandler.add(BomPlugin.API_ENFORCED_CONFIGURATION_NAME,
120+
this.dependencyHandler.enforcedPlatform(bomDependency));
117121
}
118122
}
119123
}

buildSrc/src/main/java/org/springframework/boot/build/bom/BomPlugin.java

+16
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
*/
6868
public class BomPlugin implements Plugin<Project> {
6969

70+
static final String API_ENFORCED_CONFIGURATION_NAME = "apiEnforced";
71+
7072
@Override
7173
public void apply(Project project) {
7274
PluginContainer plugins = project.getPlugins();
@@ -75,6 +77,7 @@ public void apply(Project project) {
7577
plugins.apply(JavaPlatformPlugin.class);
7678
JavaPlatformExtension javaPlatform = project.getExtensions().getByType(JavaPlatformExtension.class);
7779
javaPlatform.allowDependencies();
80+
createApiEnforcedConfiguration(project);
7881
BomExtension bom = project.getExtensions().create("bom", BomExtension.class, project.getDependencies());
7982
project.getTasks().create("bomrCheck", CheckBom.class, bom);
8083
project.getTasks().create("bomrUpgrade", UpgradeBom.class, bom);
@@ -114,6 +117,19 @@ public void apply(Project project) {
114117
});
115118
}
116119

120+
private void createApiEnforcedConfiguration(Project project) {
121+
Configuration apiEnforced = project.getConfigurations().create(API_ENFORCED_CONFIGURATION_NAME,
122+
(configuration) -> {
123+
configuration.setCanBeConsumed(false);
124+
configuration.setCanBeResolved(false);
125+
configuration.setVisible(false);
126+
});
127+
project.getConfigurations().getByName(JavaPlatformPlugin.ENFORCED_API_ELEMENTS_CONFIGURATION_NAME)
128+
.extendsFrom(apiEnforced);
129+
project.getConfigurations().getByName(JavaPlatformPlugin.ENFORCED_RUNTIME_ELEMENTS_CONFIGURATION_NAME)
130+
.extendsFrom(apiEnforced);
131+
}
132+
117133
private static final class PublishingCustomizer {
118134

119135
private final Project project;

buildSrc/src/main/java/org/springframework/boot/build/starters/StarterPlugin.java

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.springframework.boot.build.ConventionsPlugin;
3131
import org.springframework.boot.build.DeployedPlugin;
32+
import org.springframework.boot.build.InternalDependencyManagementPlugin;
3233
import org.springframework.boot.build.classpath.CheckClasspathForConflicts;
3334
import org.springframework.boot.build.classpath.CheckClasspathForProhibitedDependencies;
3435
import org.springframework.util.StringUtils;
@@ -46,6 +47,7 @@ public void apply(Project project) {
4647
plugins.apply(DeployedPlugin.class);
4748
plugins.apply(JavaLibraryPlugin.class);
4849
plugins.apply(ConventionsPlugin.class);
50+
plugins.apply(InternalDependencyManagementPlugin.class);
4951
StarterMetadata starterMetadata = project.getTasks().create("starterMetadata", StarterMetadata.class);
5052
ConfigurationContainer configurations = project.getConfigurations();
5153
Configuration runtimeClasspath = configurations.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);

spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
id 'org.springframework.boot.auto-configuration'
66
id 'org.springframework.boot.conventions'
77
id 'org.springframework.boot.deployed'
8+
id 'org.springframework.boot.internal-dependency-management'
89
id 'org.springframework.boot.optional-dependencies'
910
}
1011

@@ -16,20 +17,21 @@ configurations {
1617
}
1718

1819
dependencies {
19-
asciidoctorExtensions enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
20+
asciidoctorExtensions platform(project(':spring-boot-project:spring-boot-dependencies'))
2021
asciidoctorExtensions 'org.springframework.restdocs:spring-restdocs-asciidoctor'
2122

23+
api platform(project(':spring-boot-project:spring-boot-dependencies'))
24+
2225
api project(':spring-boot-project:spring-boot-actuator')
2326

24-
implementation enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
2527
implementation project(':spring-boot-project:spring-boot')
2628
implementation project(':spring-boot-project:spring-boot-autoconfigure')
2729
implementation 'com.fasterxml.jackson.core:jackson-databind'
2830
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
2931
implementation 'org.springframework:spring-core'
3032
implementation 'org.springframework:spring-context'
3133

32-
optional enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
34+
optional platform(project(':spring-boot-project:spring-boot-dependencies'))
3335
optional 'ch.qos.logback:logback-classic'
3436
optional 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
3537
optional 'com.github.ben-manes.caffeine:caffeine'

spring-boot-project/spring-boot-actuator/build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ plugins {
99
description = 'Spring Boot Actuator'
1010

1111
dependencies {
12-
implementation enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
12+
api platform(project(':spring-boot-project:spring-boot-dependencies'))
13+
1314
implementation project(':spring-boot-project:spring-boot')
1415

15-
optional enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
16+
optional platform(project(':spring-boot-project:spring-boot-dependencies'))
1617
optional 'com.fasterxml.jackson.core:jackson-databind'
1718
optional 'com.hazelcast:hazelcast'
1819
optional 'com.hazelcast:hazelcast-spring'

spring-boot-project/spring-boot-autoconfigure/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ plugins {
44
id 'org.springframework.boot.auto-configuration'
55
id 'org.springframework.boot.conventions'
66
id 'org.springframework.boot.deployed'
7+
id 'org.springframework.boot.internal-dependency-management'
78
id 'org.springframework.boot.optional-dependencies'
89
}
910

1011
description = 'Spring Boot AutoConfigure'
1112

1213
dependencies {
1314
api project(':spring-boot-project:spring-boot')
15+
api platform(project(':spring-boot-project:spring-boot-dependencies'))
1416

15-
implementation enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
16-
17-
optional enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
17+
optional platform(project(':spring-boot-project:spring-boot-dependencies'))
1818
optional 'com.atomikos:transactions-jdbc'
1919
optional 'com.atomikos:transactions-jta'
2020
optional 'com.couchbase.client:couchbase-spring-cache'
@@ -148,7 +148,7 @@ dependencies {
148148
optional 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
149149
optional 'redis.clients:jedis'
150150

151-
testImplementation enforcedPlatform(project(':spring-boot-project:spring-boot-parent'))
151+
testImplementation platform(project(':spring-boot-project:spring-boot-parent'))
152152
testImplementation project(':spring-boot-project:spring-boot-tools:spring-boot-test-support')
153153
testImplementation project(':spring-boot-project:spring-boot-test')
154154
testImplementation 'ch.qos.logback:logback-classic'

spring-boot-project/spring-boot-cli/build.gradle

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
id 'org.springframework.boot.deployed'
44
id 'org.springframework.boot.conventions'
55
id 'org.springframework.boot.integration-test'
6+
id 'org.springframework.boot.internal-dependency-management'
67
}
78

89
description = "Spring Boot CLI"
@@ -15,16 +16,14 @@ configurations {
1516

1617
dependencies {
1718
compileOnly project(':spring-boot-project:spring-boot')
18-
1919
compileOnly 'jakarta.servlet:jakarta.servlet-api'
2020
compileOnly 'org.codehaus.groovy:groovy-templates'
2121
compileOnly 'org.springframework:spring-web'
2222

2323
dependenciesBom project(path: ':spring-boot-project:spring-boot-dependencies', configuration: 'effectiveBom')
2424

25-
implementation enforcedPlatform(project(':spring-boot-project:spring-boot-parent'))
25+
implementation platform(project(':spring-boot-project:spring-boot-parent'))
2626
implementation project(':spring-boot-project:spring-boot-tools:spring-boot-loader-tools')
27-
2827
implementation 'com.vaadin.external.google:android-json'
2928
implementation 'jline:jline'
3029
implementation 'net.sf.jopt-simple:jopt-simple'
@@ -51,7 +50,7 @@ dependencies {
5150
implementation 'org.springframework:spring-core'
5251
implementation 'org.springframework.security:spring-security-crypto'
5352

54-
intTestImplementation enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
53+
intTestImplementation platform(project(':spring-boot-project:spring-boot-dependencies'))
5554
intTestImplementation project(':spring-boot-project:spring-boot-tools:spring-boot-loader-tools')
5655
intTestImplementation project(':spring-boot-project:spring-boot-tools:spring-boot-test-support')
5756
intTestImplementation 'org.assertj:assertj-core'

spring-boot-project/spring-boot-devtools/build.gradle

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44
id 'org.springframework.boot.conventions'
55
id 'org.springframework.boot.deployed'
66
id 'org.springframework.boot.integration-test'
7+
id 'org.springframework.boot.internal-dependency-management'
78
id 'org.springframework.boot.optional-dependencies'
89
}
910

@@ -14,13 +15,13 @@ configurations {
1415
}
1516

1617
dependencies {
17-
implementation enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
18+
api platform(project(':spring-boot-project:spring-boot-dependencies'))
19+
1820
implementation project(':spring-boot-project:spring-boot')
1921
implementation project(':spring-boot-project:spring-boot-autoconfigure')
2022

2123
intTestDependencies project(':spring-boot-project:spring-boot-starters:spring-boot-starter-web')
2224

23-
intTestImplementation enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
2425
intTestImplementation project(':spring-boot-project:spring-boot-autoconfigure')
2526
intTestImplementation project(':spring-boot-project:spring-boot-test')
2627
intTestImplementation project(':spring-boot-project:spring-boot-tools:spring-boot-test-support')
@@ -31,7 +32,7 @@ dependencies {
3132
intTestImplementation 'net.bytebuddy:byte-buddy'
3233
intTestRuntimeOnly 'org.springframework:spring-web'
3334

34-
optional enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
35+
optional platform(project(':spring-boot-project:spring-boot-dependencies'))
3536
optional 'javax.servlet:javax.servlet-api'
3637
optional 'org.apache.derby:derby'
3738
optional 'org.hibernate:hibernate-core'

spring-boot-project/spring-boot-properties-migrator/build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ plugins {
22
id 'java-library'
33
id 'maven-publish'
44
id 'org.springframework.boot.conventions'
5+
id 'org.springframework.boot.internal-dependency-management'
56
}
67

78
description = 'Spring Boot Properties Migrator'
89

910
dependencies {
10-
implementation enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
11+
api platform(project(':spring-boot-project:spring-boot-dependencies'))
12+
1113
implementation project(':spring-boot-project:spring-boot')
1214
implementation project(':spring-boot-project:spring-boot-tools:spring-boot-configuration-metadata')
1315

spring-boot-project/spring-boot-starters/spring-boot-starter-activemq/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
description = "Starter for JMS messaging using Apache ActiveMQ"
66

77
dependencies {
8-
api enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
8+
api platform(project(':spring-boot-project:spring-boot-dependencies'))
99
api project(':spring-boot-project:spring-boot-starters:spring-boot-starter')
1010
api 'org.springframework:spring-jms'
1111
api ('org.apache.activemq:activemq-broker') {

spring-boot-project/spring-boot-starters/spring-boot-starter-actuator/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
description = "Starter for using Spring Boot's Actuator which provides production ready features to help you monitor and manage your application"
66

77
dependencies {
8-
api enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
8+
api platform(project(':spring-boot-project:spring-boot-dependencies'))
99
api project(':spring-boot-project:spring-boot-starters:spring-boot-starter')
1010
api project(':spring-boot-project:spring-boot-actuator-autoconfigure')
1111
api 'io.micrometer:micrometer-core'

spring-boot-project/spring-boot-starters/spring-boot-starter-amqp/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
description = "Starter for using Spring AMQP and Rabbit MQ"
66

77
dependencies {
8-
api enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
8+
api platform(project(':spring-boot-project:spring-boot-dependencies'))
99
api project(':spring-boot-project:spring-boot-starters:spring-boot-starter')
1010
api 'org.springframework:spring-messaging'
1111
api 'org.springframework.amqp:spring-rabbit'

spring-boot-project/spring-boot-starters/spring-boot-starter-aop/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
description = "Starter for aspect-oriented programming with Spring AOP and AspectJ"
66

77
dependencies {
8-
api enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
8+
api platform(project(':spring-boot-project:spring-boot-dependencies'))
99
api project(':spring-boot-project:spring-boot-starters:spring-boot-starter')
1010
api 'org.springframework:spring-aop'
1111
api 'org.aspectj:aspectjweaver'

spring-boot-project/spring-boot-starters/spring-boot-starter-artemis/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
description = "Starter for JMS messaging using Apache Artemis"
66

77
dependencies {
8-
api enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
8+
api platform(project(':spring-boot-project:spring-boot-dependencies'))
99
api project(':spring-boot-project:spring-boot-starters:spring-boot-starter')
1010
api 'jakarta.jms:jakarta.jms-api'
1111
api 'jakarta.json:jakarta.json-api'

spring-boot-project/spring-boot-starters/spring-boot-starter-batch/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
description = "Starter for using Spring Batch"
66

77
dependencies {
8-
api enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
8+
api platform(project(':spring-boot-project:spring-boot-dependencies'))
99
api project(':spring-boot-project:spring-boot-starters:spring-boot-starter')
1010
api project(':spring-boot-project:spring-boot-starters:spring-boot-starter-jdbc')
1111
api 'org.springframework.batch:spring-batch-core'

spring-boot-project/spring-boot-starters/spring-boot-starter-cache/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
description = "Starter for using Spring Framework's caching support"
66

77
dependencies {
8-
api enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
8+
api platform(project(':spring-boot-project:spring-boot-dependencies'))
99
api project(':spring-boot-project:spring-boot-starters:spring-boot-starter')
1010
api 'org.springframework:spring-context-support'
1111
}

spring-boot-project/spring-boot-starters/spring-boot-starter-cloud-connectors/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
description = "Starter for using Spring Cloud Connectors which simplifies connecting to services in cloud platforms like Cloud Foundry and Heroku"
66

77
dependencies {
8-
api enforcedPlatform(project(':spring-boot-project:spring-boot-dependencies'))
8+
api platform(project(':spring-boot-project:spring-boot-dependencies'))
99
api project(':spring-boot-project:spring-boot-starters:spring-boot-starter')
1010
api 'org.springframework.cloud:spring-cloud-spring-service-connector'
1111
api 'org.springframework.cloud:spring-cloud-cloudfoundry-connector'

0 commit comments

Comments
 (0)