Skip to content

Commit 10e4965

Browse files
committed
Guard against new Spring modules in ApiDiff task
Prior to this commit, the ApiDiff Gradle task would be configured for all submodules of the Spring Framework project and would assume that they all existed for the baseline version considered for the API diff. This would cause issues when: * the sub-project is not published as it's not an official "spring-*" module * the "spring-*" module is new and did not exist for the baseline version This commit ensures that only "spring-*" modules are considered for this task and that we trigger an early resolution of the baseline version - if the version doesn't exist, a warn message is logged and we assume that this is a new module, to be compared with an empty configuration. This commit also renames the "spring-core-graalvm" project to "graalvm-feature", since this sub-project is not an official module published to Maven Central, but rather an internal dependency. Fixes spring-projectsgh-28818
1 parent d33c2b5 commit 10e4965

File tree

6 files changed

+32
-34
lines changed

6 files changed

+32
-34
lines changed

buildSrc/src/main/java/org/springframework/build/api/ApiDiffPlugin.java

+22-8
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,22 @@
2424

2525
import me.champeau.gradle.japicmp.JapicmpPlugin;
2626
import me.champeau.gradle.japicmp.JapicmpTask;
27-
import org.gradle.api.Action;
27+
import org.gradle.api.GradleException;
2828
import org.gradle.api.Plugin;
2929
import org.gradle.api.Project;
3030
import org.gradle.api.artifacts.Configuration;
3131
import org.gradle.api.artifacts.Dependency;
32-
import org.gradle.api.artifacts.repositories.ArtifactRepository;
33-
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
34-
import org.gradle.api.artifacts.repositories.RepositoryContentDescriptor;
3532
import org.gradle.api.plugins.JavaBasePlugin;
3633
import org.gradle.api.plugins.JavaPlugin;
3734
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
3835
import org.gradle.api.tasks.TaskProvider;
3936
import org.gradle.jvm.tasks.Jar;
37+
import org.slf4j.Logger;
38+
import org.slf4j.LoggerFactory;
4039

4140
/**
4241
* {@link Plugin} that applies the {@code "japicmp-gradle-plugin"}
43-
* and create tasks for all subprojects, diffing the public API one by one
42+
* and create tasks for all subprojects named {@code "spring-*"}, diffing the public API one by one
4443
* and creating the reports in {@code "build/reports/api-diff/$OLDVERSION_to_$NEWVERSION/"}.
4544
* <p>{@code "./gradlew apiDiff -PbaselineVersion=5.1.0.RELEASE"} will output the
4645
* reports for the API diff between the baseline version and the current one for all modules.
@@ -51,6 +50,8 @@
5150
*/
5251
public class ApiDiffPlugin implements Plugin<Project> {
5352

53+
private static final Logger logger = LoggerFactory.getLogger(ApiDiffPlugin.class);
54+
5455
public static final String TASK_NAME = "apiDiff";
5556

5657
private static final String BASELINE_VERSION_PROPERTY = "baselineVersion";
@@ -70,7 +71,11 @@ public void apply(Project project) {
7071

7172
private void applyApiDiffConventions(Project project) {
7273
String baselineVersion = project.property(BASELINE_VERSION_PROPERTY).toString();
73-
project.subprojects(subProject -> createApiDiffTask(baselineVersion, subProject));
74+
project.subprojects(subProject -> {
75+
if (subProject.getName().startsWith("spring-")) {
76+
createApiDiffTask(baselineVersion, subProject);
77+
}
78+
});
7479
}
7580

7681
private void createApiDiffTask(String baselineVersion, Project project) {
@@ -83,7 +88,7 @@ private void createApiDiffTask(String baselineVersion, Project project) {
8388
apiDiff.setDescription("Generates an API diff report with japicmp");
8489
apiDiff.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
8590

86-
apiDiff.setOldClasspath(project.files(createBaselineConfiguration(baselineVersion, project)));
91+
apiDiff.setOldClasspath(createBaselineConfiguration(baselineVersion, project));
8792
TaskProvider<Jar> jar = project.getTasks().withType(Jar.class).named("jar");
8893
apiDiff.setNewArchives(project.getLayout().files(jar.get().getArchiveFile().get().getAsFile()));
8994
apiDiff.setNewClasspath(getRuntimeClassPath(project));
@@ -109,7 +114,16 @@ private Configuration createBaselineConfiguration(String baselineVersion, Projec
109114
String baseline = String.join(":",
110115
project.getGroup().toString(), project.getName(), baselineVersion);
111116
Dependency baselineDependency = project.getDependencies().create(baseline + "@jar");
112-
return project.getRootProject().getConfigurations().detachedConfiguration(baselineDependency);
117+
Configuration baselineConfiguration = project.getRootProject().getConfigurations().detachedConfiguration(baselineDependency);
118+
try {
119+
// eagerly resolve the baseline configuration to check whether this is a new Spring module
120+
baselineConfiguration.resolve();
121+
return baselineConfiguration;
122+
}
123+
catch (GradleException exception) {
124+
logger.warn("Could not resolve {} - assuming this is a new Spring module.", baseline);
125+
}
126+
return project.getRootProject().getConfigurations().detachedConfiguration();
113127
}
114128

115129
private Configuration getRuntimeClassPath(Project project) {

framework-bom/framework-bom.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ group = "org.springframework"
77

88
dependencies {
99
constraints {
10-
parent.moduleProjects.findAll{ it.name != 'spring-core-graalvm' }.sort { "$it.name" }.each {
10+
parent.moduleProjects.sort { "$it.name" }.each {
1111
api it
1212
}
1313
}

gradle/docs.gradle

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
ext {
2-
documentedProjects = moduleProjects.findAll { it.name != 'spring-core-graalvm' }
3-
}
4-
51
configurations {
62
asciidoctorExt
73
}
@@ -28,7 +24,7 @@ task api(type: Javadoc) {
2824
title = "${rootProject.description} ${version} API"
2925

3026
dependsOn {
31-
documentedProjects.collect {
27+
moduleProjects.collect {
3228
it.tasks.getByName("jar")
3329
}
3430
}
@@ -37,7 +33,7 @@ task api(type: Javadoc) {
3733
// ensure the javadoc process can resolve types compiled from .aj sources
3834
project(":spring-aspects").sourceSets.main.output
3935
)
40-
classpath += files(documentedProjects.collect { it.sourceSets.main.compileClasspath })
36+
classpath += files(moduleProjects.collect { it.sourceSets.main.compileClasspath })
4137
}
4238

4339
options {
@@ -52,7 +48,7 @@ task api(type: Javadoc) {
5248
addBooleanOption('Xdoclint:syntax', true) // only check syntax with doclint
5349
addBooleanOption('Werror', true) // fail build on Javadoc warnings
5450
}
55-
source documentedProjects.collect { project ->
51+
source moduleProjects.collect { project ->
5652
project.sourceSets.main.allJava
5753
}
5854
maxMemory = "1024m"
@@ -184,7 +180,7 @@ task schemaZip(type: Zip) {
184180
description = "Builds -${archiveClassifier} archive containing all " +
185181
"XSDs for deployment at https://springframework.org/schema."
186182
duplicatesStrategy DuplicatesStrategy.EXCLUDE
187-
documentedProjects.each { module ->
183+
moduleProjects.each { module ->
188184
def Properties schemas = new Properties();
189185

190186
module.sourceSets.main.resources.find {
@@ -234,7 +230,7 @@ task distZip(type: Zip, dependsOn: [docsZip, schemaZip]) {
234230
into "${baseDir}/schema"
235231
}
236232

237-
documentedProjects.each { module ->
233+
moduleProjects.each { module ->
238234
into ("${baseDir}/libs") {
239235
from module.jar
240236
if (module.tasks.findByPath("sourcesJar")) {
@@ -247,4 +243,4 @@ task distZip(type: Zip, dependsOn: [docsZip, schemaZip]) {
247243
}
248244
}
249245

250-
distZip.mustRunAfter documentedProjects.check
246+
distZip.mustRunAfter moduleProjects.check

settings.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ include "spring-context"
1818
include "spring-context-indexer"
1919
include "spring-context-support"
2020
include "spring-core"
21-
include "spring-core-graalvm"
22-
project(':spring-core-graalvm').projectDir = file('spring-core/graalvm')
21+
include "graalvm-feature"
22+
project(':graalvm-feature').projectDir = file('spring-core/graalvm')
2323
include "spring-core-test"
2424
include "spring-expression"
2525
include "spring-instrument"

spring-core/graalvm/spring-core-graalvm.gradle spring-core/graalvm/graalvm-feature.gradle

-12
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,3 @@ eclipse.classpath.file {
3434
dependencies {
3535
compileOnly("org.graalvm.nativeimage:svm")
3636
}
37-
38-
tasks.withType(PublishToMavenRepository) {
39-
enabled = false
40-
}
41-
42-
tasks.withType(PublishToMavenLocal) {
43-
enabled = false
44-
}
45-
46-
tasks.withType(Javadoc) {
47-
enabled = false
48-
}

spring-core/spring-core.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ dependencies {
4545
cglib("cglib:cglib:${cglibVersion}@jar")
4646
javapoet("com.squareup:javapoet:${javapoetVersion}@jar")
4747
objenesis("org.objenesis:objenesis:${objenesisVersion}@jar")
48-
graalvm(project(path: ":spring-core-graalvm", configuration: 'classesOnlyElements'))
48+
graalvm(project(path: ":graalvm-feature", configuration: 'classesOnlyElements'))
4949
api(files(cglibRepackJar))
5050
api(files(javapoetRepackJar))
5151
api(files(objenesisRepackJar))

0 commit comments

Comments
 (0)