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 9d59c158..baf4bd39 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,4 +18,62 @@ class VerifyReleaseIntegrationTest extends BaseIntegrationTest { result.task(":verifyRelease").outcome == TaskOutcome.SUCCESS } + def "should work in multimodule project setup"() { + given: + initialMultiModuleProjectConfiguration() + + when: + def result = runGradle(':verifyRelease') + + then: + result.task(":verifyRelease").outcome == TaskOutcome.SUCCESS + } + + void initialMultiModuleProjectConfiguration() { + buildFile(''' + scmVersion { + versionCreator "versionWithBranch" + } + allprojects { + 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) { + File submoduleDir = new File(temporaryFolder, projectName) + submoduleDir.mkdirs() + File buildFile = new File(submoduleDir, "build.gradle") + buildFile << ''' + plugins { + id 'java-platform' + } + + dependencies { + constraints { + api "multimodule-project:multimodule-project:${version}" + } + } + ''' + } + + void generateSettingsFile(File dir) { + File settings = new File(dir, "settings.gradle") + settings << """ + rootProject.name = "multimodule-project" + include(':module1') + """ + } + + void generateGitIgnoreFile(File dir) { + File gitIgnore = new File(dir, ".gitignore") + gitIgnore << """\ + .gradle + """.stripIndent() + } } diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/SnapshotDependenciesChecker.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/domain/SnapshotDependenciesChecker.groovy deleted file mode 100644 index eb27ee33..00000000 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/domain/SnapshotDependenciesChecker.groovy +++ /dev/null @@ -1,40 +0,0 @@ -package pl.allegro.tech.build.axion.release.domain - -import org.gradle.api.Project -import org.gradle.api.artifacts.Configuration -import org.gradle.api.artifacts.Dependency -import org.gradle.api.artifacts.DependencyConstraint - -class SnapshotDependenciesChecker { - - Collection snapshotVersions(Project project) { - Collection projectVersions = project.getRootProject().getAllprojects() - .collect { toFullVersion(it) } - Collection configurations = project.getRootProject().getAllprojects() - .collect { it.getConfigurations() }.flatten() as Collection - Collection allDependenciesVersions = new HashSet<>() - for (Configuration config : configurations) { - Collection versions = config.getAllDependencies() - .findAll { isSnapshot(it) } - .collect { toFullVersion(it) } - +config.getAllDependencyConstraints() - .findAll { isSnapshot(it) } - .collect { toFullVersion(it) } - allDependenciesVersions.addAll(versions) - } - allDependenciesVersions.removeAll(projectVersions) - return allDependenciesVersions - } - - boolean isSnapshot(Dependency dependency) { - dependency.version?.endsWith("-SNAPSHOT") - } - - boolean isSnapshot(DependencyConstraint dependency) { - dependency.version?.endsWith("-SNAPSHOT") - } - - String toFullVersion(it) { - "${it.group}:${it.name}:${it.version}".toString() - } -} 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 new file mode 100644 index 00000000..c257b278 --- /dev/null +++ b/src/main/java/pl/allegro/tech/build/axion/release/domain/SnapshotDependenciesChecker.java @@ -0,0 +1,61 @@ +package pl.allegro.tech.build.axion.release.domain; + +import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.DependencyConstraint; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; + +public class SnapshotDependenciesChecker { + + public Collection snapshotVersions(Project project) { + Set projectVersions = project.getRootProject().getAllprojects().stream() + .map(this::toFullVersion) + .collect(Collectors.toSet()); + + Set configurations = project.getRootProject().getAllprojects().stream() + .flatMap(p -> p.getConfigurations().stream()) + .collect(Collectors.toSet()); + + Set allDependenciesVersions = new HashSet<>(); + for (Configuration config : configurations) { + Set versions = config.getAllDependencies().stream() + .filter(this::isSnapshot) + .map(this::toFullVersion) + .collect(Collectors.toSet()); + + Set constraintVersions = config.getAllDependencyConstraints().stream() + .filter(this::isSnapshot) + .map(this::toFullVersion) + .collect(Collectors.toSet()); + + allDependenciesVersions.addAll(versions); + allDependenciesVersions.addAll(constraintVersions); + } + allDependenciesVersions.removeAll(projectVersions); + return allDependenciesVersions; + } + + private boolean isSnapshot(Dependency dependency) { + return dependency.getVersion() != null && dependency.getVersion().endsWith("-SNAPSHOT"); + } + + private boolean isSnapshot(DependencyConstraint dependency) { + return dependency.getVersion() != null && dependency.getVersion().endsWith("-SNAPSHOT"); + } + + private String toFullVersion(Object it) { + if (it instanceof Dependency) { + Dependency dependency = (Dependency) it; + return String.format("%s:%s:%s", dependency.getGroup(), dependency.getName(), dependency.getVersion()); + } else if (it instanceof DependencyConstraint) { + DependencyConstraint constraint = (DependencyConstraint) it; + return String.format("%s:%s:%s", constraint.getGroup(), constraint.getName(), constraint.getVersion()); + } + return ""; + } +}