From 0e15a626e2ed6c0527f851bb3d71ad4e7bdda36f Mon Sep 17 00:00:00 2001 From: Mike Sou <33867885+imvs@users.noreply.github.com> Date: Mon, 23 Sep 2024 10:46:07 +0300 Subject: [PATCH] Fix ConcurrentModificationException in SnapshotDependenciesChecker (#819) * Fix ConcurrentModificationException * Fix ConcurrentModificationException --------- Co-authored-by: saukhmv --- .../domain/SnapshotDependenciesChecker.groovy | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) 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 index 61cf8fc8..eb27ee33 100644 --- 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 @@ -1,20 +1,27 @@ 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.rootProject.allprojects.collect {toFullVersion(it)} - Collection allDependenciesVersions = project.allprojects.collect { - it.configurations.collect { config -> - config.allDependencies.findAll {isSnapshot(it)}.collect {toFullVersion(it)}+ - config.allDependencyConstraints.findAll {isSnapshot(it)}.collect {toFullVersion(it)} - - } - }.flatten().unique() + 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 } @@ -22,6 +29,7 @@ class SnapshotDependenciesChecker { boolean isSnapshot(Dependency dependency) { dependency.version?.endsWith("-SNAPSHOT") } + boolean isSnapshot(DependencyConstraint dependency) { dependency.version?.endsWith("-SNAPSHOT") }