Skip to content

Commit

Permalink
graadle module dependnecies that have the same version as root projec…
Browse files Browse the repository at this point in the history
…t should not be detected as snapshots | fixes #827
  • Loading branch information
bgalek committed Oct 4, 2024
1 parent a158fe6 commit a701223
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,57 @@ 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('''
allprojects {
scmVersion {
tag {
prefix = name
}
}
version = scmVersion.version
}
''')
generateSettingsFile(temporaryFolder)
generateGitIgnoreFile(temporaryFolder)
generateSubmoduleBuildFile("module1")
repository.commit(['.'], "initial commit of top level project")
runGradle(":createRelease", "-Prelease.version=1.0.0", '-Prelease.disableChecks')
}

void generateSubmoduleBuildFile(String projectName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +56,10 @@ 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);
String projectGroupOrRootProjectGroup = project.getGroup() == "" ? project.getRootProject().getName() : project.getName();
return String.format("%s:%s:%s", projectGroupOrRootProjectGroup, project.getName(), project.getRootProject().getVersion());
}
return "";
}
Expand Down

0 comments on commit a701223

Please sign in to comment.