From 66554ec811bb88242cc9155eaeb79d949560e8d0 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 5 Mar 2026 18:23:16 +0000 Subject: [PATCH] Make snapshot deps available to Maven Plugin integration tests See gh-49396 --- .../boot/build/MavenRepositoryPlugin.java | 39 +++++++++++++---- .../build/mavenplugin/MavenPluginPlugin.java | 43 ++++++++++--------- .../spring-boot-maven-plugin/build.gradle | 1 + 3 files changed, 54 insertions(+), 29 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/MavenRepositoryPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/MavenRepositoryPlugin.java index aacc8447632..6c031b1c8bd 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/MavenRepositoryPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/MavenRepositoryPlugin.java @@ -23,8 +23,11 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.DependencySet; +import org.gradle.api.artifacts.ModuleDependency; import org.gradle.api.artifacts.ProjectDependency; +import org.gradle.api.attributes.Category; import org.gradle.api.plugins.JavaLibraryPlugin; import org.gradle.api.plugins.JavaPlatformPlugin; import org.gradle.api.plugins.JavaPlugin; @@ -77,19 +80,20 @@ public class MavenRepositoryPlugin implements Plugin { DependencySet target = projectRepository.getDependencies(); project.getPlugins() .withType(JavaPlugin.class) - .all((javaPlugin) -> addMavenRepositoryDependencies(project, JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, - target)); + .all((javaPlugin) -> addMavenRepositoryProjectDependencies(project, + JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, target)); project.getPlugins() .withType(JavaLibraryPlugin.class) - .all((javaLibraryPlugin) -> addMavenRepositoryDependencies(project, JavaPlugin.API_CONFIGURATION_NAME, - target)); - project.getPlugins() - .withType(JavaPlatformPlugin.class) - .all((javaPlugin) -> addMavenRepositoryDependencies(project, JavaPlatformPlugin.API_CONFIGURATION_NAME, - target)); + .all((javaLibraryPlugin) -> addMavenRepositoryProjectDependencies(project, + JavaPlugin.API_CONFIGURATION_NAME, target)); + project.getPlugins().withType(JavaPlatformPlugin.class).all((javaPlugin) -> { + addMavenRepositoryProjectDependencies(project, JavaPlatformPlugin.API_CONFIGURATION_NAME, target); + addMavenRepositoryPlatformDependencies(project, JavaPlatformPlugin.API_CONFIGURATION_NAME, target); + }); } - private void addMavenRepositoryDependencies(Project project, String sourceConfigurationName, DependencySet target) { + private void addMavenRepositoryProjectDependencies(Project project, String sourceConfigurationName, + DependencySet target) { project.getConfigurations() .getByName(sourceConfigurationName) .getDependencies() @@ -103,6 +107,23 @@ public class MavenRepositoryPlugin implements Plugin { }); } + private void addMavenRepositoryPlatformDependencies(Project project, String sourceConfigurationName, + DependencySet target) { + project.getConfigurations() + .getByName(sourceConfigurationName) + .getDependencies() + .withType(ModuleDependency.class) + .matching((dependency) -> { + Category category = dependency.getAttributes().getAttribute(Category.CATEGORY_ATTRIBUTE); + return Category.REGULAR_PLATFORM.equals(category.getName()); + }) + .all((dependency) -> { + Dependency pom = project.getDependencies() + .create(dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion()); + target.add(pom); + }); + } + private static final class CleanAction implements Action { private final File location; diff --git a/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java index a5b1f4ae255..79d9780ac13 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java @@ -161,22 +161,25 @@ public class MavenPluginPlugin implements Plugin { } private void addPopulateIntTestMavenRepositoryTask(Project project) { - Configuration runtimeClasspathWithMetadata = project.getConfigurations().create("runtimeClasspathWithMetadata"); - runtimeClasspathWithMetadata - .extendsFrom(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)); - runtimeClasspathWithMetadata.attributes((attributes) -> attributes.attribute(DocsType.DOCS_TYPE_ATTRIBUTE, - project.getObjects().named(DocsType.class, "maven-repository"))); - TaskProvider runtimeClasspathMavenRepository = project.getTasks() - .register("runtimeClasspathMavenRepository", RuntimeClasspathMavenRepository.class, - (task) -> task.getOutputDir() - .set(project.getLayout().getBuildDirectory().dir("runtime-classpath-repository"))); + Configuration repositoryContents = project.getConfigurations().create("repositoryContents"); + repositoryContents.extendsFrom( + project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME), + project.getConfigurations().getByName("mavenRepository")); + repositoryContents.setCanBeConsumed(false); + TaskProvider populateMavenRepository = project.getTasks() + .register("populateResolvedDependenciesMavenRepository", ResolvedConfigurationMavenRepository.class, + (task) -> { + task.setConfiguration(repositoryContents); + task.getOutputDir() + .set(project.getLayout().getBuildDirectory().dir("resolved-dependencies-maven-repository")); + }); project.getDependencies() .components((components) -> components.all(MavenRepositoryComponentMetadataRule.class)); TaskProvider populateRepository = project.getTasks() .register("populateTestMavenRepository", Sync.class, (task) -> { task.setDestinationDir( project.getLayout().getBuildDirectory().dir("test-maven-repository").get().getAsFile()); - task.with(copyIntTestMavenRepositoryFiles(project, runtimeClasspathMavenRepository)); + task.with(copyIntTestMavenRepositoryFiles(project, populateMavenRepository)); task.dependsOn( project.getTasks().getByName(MavenRepositoryPlugin.PUBLISH_TO_PROJECT_REPOSITORY_TASK_NAME)); }); @@ -189,7 +192,7 @@ public class MavenPluginPlugin implements Plugin { } private CopySpec copyIntTestMavenRepositoryFiles(Project project, - TaskProvider runtimeClasspathMavenRepository) { + TaskProvider runtimeClasspathMavenRepository) { CopySpec copySpec = project.copySpec(); copySpec.from(project.getConfigurations().getByName(MavenRepositoryPlugin.MAVEN_REPOSITORY_CONFIGURATION_NAME)); copySpec.from(project.getLayout().getBuildDirectory().dir("maven-repository")); @@ -418,25 +421,25 @@ public class MavenPluginPlugin implements Plugin { } - public abstract static class RuntimeClasspathMavenRepository extends DefaultTask { + public abstract static class ResolvedConfigurationMavenRepository extends DefaultTask { - private final Configuration runtimeClasspath; - - public RuntimeClasspathMavenRepository() { - this.runtimeClasspath = getProject().getConfigurations().getByName("runtimeClasspathWithMetadata"); - } + private Configuration configuration; @OutputDirectory public abstract DirectoryProperty getOutputDir(); @Classpath - public Configuration getRuntimeClasspath() { - return this.runtimeClasspath; + public Configuration getConfiguration() { + return this.configuration; + } + + public void setConfiguration(Configuration configuration) { + this.configuration = configuration; } @TaskAction public void createRepository() { - for (ResolvedArtifactResult result : this.runtimeClasspath.getIncoming().getArtifacts()) { + for (ResolvedArtifactResult result : this.configuration.getIncoming().getArtifacts()) { if (result.getId().getComponentIdentifier() instanceof ModuleComponentIdentifier identifier) { String fileName = result.getFile() .getName() diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle index 355c3b9d204..e31a3ca2ca7 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle @@ -95,6 +95,7 @@ dependencies { mavenRepository(project(path: ":spring-boot-project:spring-boot-devtools", configuration: "mavenRepository")) mavenRepository(project(path: ":spring-boot-project:spring-boot-docker-compose", configuration: "mavenRepository")) mavenRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-parent", configuration: "mavenRepository")) + mavenRepository("org.springframework:spring-test") versionProperties(project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "resolvedBom")) }