From 2d9c9fe9cca01f0851158424134467e96f6debcf Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 13 Jan 2022 12:24:39 +0100 Subject: [PATCH] Configure Spring Milestone repository for apiDiff task Prior to this commit, the `apiDiff` custom Gradle task would only use the configured repositories in the build to generated the API diff report. This causes issues when the report has to be generated against a previous milestone: the Spring Framework build only relies on Maven Central and a specific `libs-spring-framework-build` repository for building the project. In this case, the task cannot resolve the previous milestone artifacts to generate the report. This commit improves the `ApiDiffPlugin` to automatically add the Spring Milestone repository to the root project configuration when the task is executed. Fixes gh-27928 --- .../org/springframework/build/api/ApiDiffPlugin.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/buildSrc/src/main/java/org/springframework/build/api/ApiDiffPlugin.java b/buildSrc/src/main/java/org/springframework/build/api/ApiDiffPlugin.java index 931fd102211..bebd656bf2d 100644 --- a/buildSrc/src/main/java/org/springframework/build/api/ApiDiffPlugin.java +++ b/buildSrc/src/main/java/org/springframework/build/api/ApiDiffPlugin.java @@ -16,6 +16,7 @@ package org.springframework.build.api; import java.io.File; +import java.net.URI; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; @@ -23,10 +24,14 @@ import java.util.List; import me.champeau.gradle.japicmp.JapicmpPlugin; import me.champeau.gradle.japicmp.JapicmpTask; +import org.gradle.api.Action; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.repositories.ArtifactRepository; +import org.gradle.api.artifacts.repositories.MavenArtifactRepository; +import org.gradle.api.artifacts.repositories.RepositoryContentDescriptor; import org.gradle.api.plugins.JavaBasePlugin; import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.publish.maven.plugins.MavenPublishPlugin; @@ -52,6 +57,8 @@ public class ApiDiffPlugin implements Plugin { private static final List PACKAGE_INCLUDES = Collections.singletonList("org.springframework.*"); + private static final URI SPRING_MILESTONE_REPOSITORY = URI.create("https://repo.spring.io/milestone"); + @Override public void apply(Project project) { if (project.hasProperty(BASELINE_VERSION_PROPERTY) && project.equals(project.getRootProject())) { @@ -68,6 +75,10 @@ public class ApiDiffPlugin implements Plugin { private void createApiDiffTask(String baselineVersion, Project project) { if (isProjectEligible(project)) { + // Add Spring Milestone repository for generating diffs against previous milestones + project.getRootProject() + .getRepositories() + .maven(mavenArtifactRepository -> mavenArtifactRepository.setUrl(SPRING_MILESTONE_REPOSITORY)); JapicmpTask apiDiff = project.getTasks().create(TASK_NAME, JapicmpTask.class); apiDiff.setDescription("Generates an API diff report with japicmp"); apiDiff.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);