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 fe48fe0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ 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')
Expand All @@ -29,20 +29,56 @@ class VerifyReleaseIntegrationTest extends BaseIntegrationTest {
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:
result.task(":verifyRelease").outcome == TaskOutcome.SUCCESS
}

void initialMultiModuleSingleVersionProjectConfiguration() {
buildFile('''
scmVersion {
versionCreator "versionWithBranch"
apply plugin: 'java'
allprojects {
version = scmVersion.version
}
dependencies {
implementation(project(":module1"))
}
''')
generateSettingsFile(temporaryFolder)
generateGitIgnoreFile(temporaryFolder)
generateSubmoduleBuildFile("module1")
repository.commit(['.'], "initial commit of top level project")
}

void initialMultiModuleMultiVersionProjectConfiguration() {
buildFile('''
apply plugin: 'java'
allprojects {
scmVersion {
tag {
prefix = name
}
}
version = scmVersion.version
}
dependencies {
implementation(project(":module1"))
}
''')
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 All @@ -53,12 +89,6 @@ class VerifyReleaseIntegrationTest extends BaseIntegrationTest {
plugins {
id 'java-platform'
}
dependencies {
constraints {
api "multimodule-project:multimodule-project:${version}"
}
}
'''
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.DependencyConstraint;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependencyConstraint;

import java.util.Collection;
import java.util.HashSet;
Expand All @@ -13,30 +15,27 @@
public class SnapshotDependenciesChecker {

public Collection<String> snapshotVersions(Project project) {
Set<String> projectVersions = project.getRootProject().getAllprojects().stream()
.map(this::toFullVersion)
.collect(Collectors.toSet());

Set<Configuration> configurations = project.getRootProject().getAllprojects().stream()
.flatMap(p -> p.getConfigurations().stream())
.collect(Collectors.toSet());

Set<String> allDependenciesVersions = new HashSet<>();
for (Configuration config : configurations) {
Set<String> versions = config.getAllDependencies().stream()
.filter(it -> !(it instanceof ProjectDependency))
.filter(this::isSnapshot)
.map(this::toFullVersion)
.collect(Collectors.toSet());

Set<String> constraintVersions = config.getAllDependencyConstraints().stream()
.filter(it -> !(it instanceof DefaultProjectDependencyConstraint))
.filter(this::isSnapshot)
.map(this::toFullVersion)
.collect(Collectors.toSet());

allDependenciesVersions.addAll(versions);
allDependenciesVersions.addAll(constraintVersions);
}
allDependenciesVersions.removeAll(projectVersions);
return allDependenciesVersions;
}

Expand Down

0 comments on commit fe48fe0

Please sign in to comment.