From e4dab4a95940294e7cf4a6f6217b4325b9b4296e Mon Sep 17 00:00:00 2001 From: Bartosz Galek Date: Fri, 4 Oct 2024 12:05:40 +0200 Subject: [PATCH] graadle module dependnecies that have the same version as root project should not be detected as snapshots | fixes #827 --- .../VerifyReleaseIntegrationTest.groovy | 34 +++++++++++++++++-- .../domain/SnapshotDependenciesChecker.java | 4 +++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/integration/groovy/pl/allegro/tech/build/axion/release/VerifyReleaseIntegrationTest.groovy b/src/integration/groovy/pl/allegro/tech/build/axion/release/VerifyReleaseIntegrationTest.groovy index baf4bd39..da3c99f0 100644 --- a/src/integration/groovy/pl/allegro/tech/build/axion/release/VerifyReleaseIntegrationTest.groovy +++ b/src/integration/groovy/pl/allegro/tech/build/axion/release/VerifyReleaseIntegrationTest.groovy @@ -18,18 +18,46 @@ class VerifyReleaseIntegrationTest extends BaseIntegrationTest { result.task(":verifyRelease").outcome == TaskOutcome.SUCCESS } - def "should work in multimodule project setup"() { + def "should work in multimodule project setup versioning every module separately"() { given: - initialMultiModuleProjectConfiguration() + initialMultiModuleMultiVersionProjectConfiguration() when: def result = runGradle(':verifyRelease') then: + // no snapshot modules allowed by default result.task(":verifyRelease").outcome == TaskOutcome.SUCCESS } - void initialMultiModuleProjectConfiguration() { + def "should work in multimodule project setup with the same version for every module"() { + given: + initialMultiModuleSingleVersionProjectConfiguration() + + when: + def result = runGradle(':verifyRelease') + + then: + // snapshot modules with the same version as root project are ok + result.task(":verifyRelease").outcome == TaskOutcome.SUCCESS + } + + void initialMultiModuleSingleVersionProjectConfiguration() { + buildFile(''' + scmVersion { + versionCreator "versionWithBranch" + } + allprojects { + version = scmVersion.version + } + ''') + generateSettingsFile(temporaryFolder) + generateGitIgnoreFile(temporaryFolder) + generateSubmoduleBuildFile("module1") + repository.commit(['.'], "initial commit of top level project") + } + + void initialMultiModuleMultiVersionProjectConfiguration() { buildFile(''' scmVersion { versionCreator "versionWithBranch" diff --git a/src/main/java/pl/allegro/tech/build/axion/release/domain/SnapshotDependenciesChecker.java b/src/main/java/pl/allegro/tech/build/axion/release/domain/SnapshotDependenciesChecker.java index c257b278..b9d2919e 100644 --- a/src/main/java/pl/allegro/tech/build/axion/release/domain/SnapshotDependenciesChecker.java +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/SnapshotDependenciesChecker.java @@ -4,6 +4,7 @@ import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.DependencyConstraint; +import org.gradle.api.internal.project.DefaultProject; import java.util.Collection; import java.util.HashSet; @@ -55,6 +56,9 @@ private String toFullVersion(Object it) { } else if (it instanceof DependencyConstraint) { DependencyConstraint constraint = (DependencyConstraint) it; return String.format("%s:%s:%s", constraint.getGroup(), constraint.getName(), constraint.getVersion()); + } else if (it instanceof DefaultProject) { + DefaultProject project = ((DefaultProject) it); + return String.format("%s:%s:%s", project.getGroup(), project.getName(), project.getRootProject().getVersion()); } return ""; }