Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add allDependencyConstraints to config #365

Merged
merged 2 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package pl.allegro.tech.build.axion.release.domain

import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.DependencyConstraint

class SnapshotDependenciesChecker {

Collection<String> snapshotVersions(Project project) {
Collection<String> projectVersions = project.allprojects.collect {toFullVersion(it)}
Collection<String> allDependenciesVersions = project.allprojects.collect {
it.configurations.collect { config ->
config.allDependencies.findAll {isSnapshot(it)}.collect {toFullVersion(it)}
config.allDependencies.findAll {isSnapshot(it)}.collect {toFullVersion(it)}+
config.allDependencyConstraints.findAll {isSnapshot(it)}.collect {toFullVersion(it)}

}
}.flatten().unique()
Expand All @@ -20,6 +22,9 @@ class SnapshotDependenciesChecker {
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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package pl.allegro.tech.build.axion.release.domain

import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Before
import org.junit.Test
import static org.junit.Assert.assertTrue

class SnapshotDependenciesCheckerTest {

SnapshotDependenciesChecker checker
Project project

@Before
void setup(){
ProjectBuilder builder = ProjectBuilder.builder()
project= builder.build()
project.configurations { implementation }
checker = new SnapshotDependenciesChecker();
}

@Test
void shouldDetectSnapshotVersions() {

project.dependencies {
implementation group: 'cicd', name:'sample', version: '2.0.3-SNAPSHOT'
}
Collection<String> snapshotVersions = checker.snapshotVersions(project)
assertTrue("SNAPSHOT dependency entry not detected",!snapshotVersions.isEmpty())
}

@Test
void shouldDetectConstraintsSnapshotVersions() {

project.dependencies {
constraints{
implementation group: 'cicd', name:'sample', version: '2.0.3-SNAPSHOT'
}
}
Collection<String> snapshotVersions = checker.snapshotVersions(project)
assertTrue("SNAPSHOT dependency entry not detected",!snapshotVersions.isEmpty())
}
}