From 2fe6aa5a5b1e9970cb7aed8eeb2093a50982358d Mon Sep 17 00:00:00 2001 From: Austin Arbor Date: Sun, 20 Oct 2024 17:25:35 -0400 Subject: [PATCH 1/3] add ability to generate a bom entry in the catalog --- .../kotlin/dev/aga/gradle/versioncatalogs/Generator.kt | 10 ++++++++++ .../dev/aga/gradle/versioncatalogs/GeneratorConfig.kt | 3 +++ .../dev/aga/gradle/versioncatalogs/GeneratorTest.kt | 1 + .../expectations/assertj-bom/both-exclusion-test.toml | 1 + .../test/resources/expectations/assertj-bom/empty.toml | 1 + .../assertj-bom/exclusion-negative-test.toml | 1 + .../expectations/assertj-bom/name-exclusion-test.toml | 1 + .../spring-boot-dependencies/libs.versions.toml | 1 + .../spring-boot-dependencies/property-overrides.toml | 1 + 9 files changed, 20 insertions(+) diff --git a/plugin/src/main/kotlin/dev/aga/gradle/versioncatalogs/Generator.kt b/plugin/src/main/kotlin/dev/aga/gradle/versioncatalogs/Generator.kt index d4c86a7..acec8ac 100644 --- a/plugin/src/main/kotlin/dev/aga/gradle/versioncatalogs/Generator.kt +++ b/plugin/src/main/kotlin/dev/aga/gradle/versioncatalogs/Generator.kt @@ -111,6 +111,16 @@ object Generator { val queue = ArrayDeque(listOf(bomDep)) val container = TomlContainer() var rootDep = true + if (config.generateBomEntry) { + createLibrary( + bomDep, + Version(bomDep.version, bomDep.version, bomDep.version), + config, + true, + container, + ) + } + while (queue.isNotEmpty()) { val dep = queue.removeFirst() val (model, parentModel) = resolver.resolve(dep) diff --git a/plugin/src/main/kotlin/dev/aga/gradle/versioncatalogs/GeneratorConfig.kt b/plugin/src/main/kotlin/dev/aga/gradle/versioncatalogs/GeneratorConfig.kt index 9d7de08..22361e4 100644 --- a/plugin/src/main/kotlin/dev/aga/gradle/versioncatalogs/GeneratorConfig.kt +++ b/plugin/src/main/kotlin/dev/aga/gradle/versioncatalogs/GeneratorConfig.kt @@ -73,6 +73,9 @@ class GeneratorConfig(val settings: Settings) { */ var excludeNames: String? = null + /** When true, an entry for the BOM itself will be added to the catalog. */ + var generateBomEntry: Boolean = false + /** * The directory to store our cached TOML file. By default, it will be stored in * `build/catalogs` relative to the directory of where the settings file exists. When diff --git a/plugin/src/test/kotlin/dev/aga/gradle/versioncatalogs/GeneratorTest.kt b/plugin/src/test/kotlin/dev/aga/gradle/versioncatalogs/GeneratorTest.kt index 6bcadb4..b04b6fc 100644 --- a/plugin/src/test/kotlin/dev/aga/gradle/versioncatalogs/GeneratorTest.kt +++ b/plugin/src/test/kotlin/dev/aga/gradle/versioncatalogs/GeneratorTest.kt @@ -119,6 +119,7 @@ internal class GeneratorTest { } cacheDirectory = projectDir cacheEnabled = true + generateBomEntry = true } val resolver = MockGradleDependencyResolver(resourceRoot.resolve("poms")) diff --git a/plugin/src/test/resources/expectations/assertj-bom/both-exclusion-test.toml b/plugin/src/test/resources/expectations/assertj-bom/both-exclusion-test.toml index 50e21e2..ab88af0 100644 --- a/plugin/src/test/resources/expectations/assertj-bom/both-exclusion-test.toml +++ b/plugin/src/test/resources/expectations/assertj-bom/both-exclusion-test.toml @@ -1,6 +1,7 @@ [versions] [libraries] +assertj-assertjBom = { group = "org.assertj", name = "assertj-bom", version = "3.24.2" } assertj-assertjGuava = { group = "org.assertj", name = "assertj-guava", version = "3.24.2" } [bundles] diff --git a/plugin/src/test/resources/expectations/assertj-bom/empty.toml b/plugin/src/test/resources/expectations/assertj-bom/empty.toml index 767305e..1f4e5fb 100644 --- a/plugin/src/test/resources/expectations/assertj-bom/empty.toml +++ b/plugin/src/test/resources/expectations/assertj-bom/empty.toml @@ -1,5 +1,6 @@ [versions] [libraries] +assertj-assertjBom = { group = "org.assertj", name = "assertj-bom", version = "3.24.2" } [bundles] diff --git a/plugin/src/test/resources/expectations/assertj-bom/exclusion-negative-test.toml b/plugin/src/test/resources/expectations/assertj-bom/exclusion-negative-test.toml index 723627b..6fca0ca 100644 --- a/plugin/src/test/resources/expectations/assertj-bom/exclusion-negative-test.toml +++ b/plugin/src/test/resources/expectations/assertj-bom/exclusion-negative-test.toml @@ -1,6 +1,7 @@ [versions] [libraries] +assertj-assertjBom = { group = "org.assertj", name = "assertj-bom", version = "3.24.2" } assertj-assertjCore = { group = "org.assertj", name = "assertj-core", version = "3.24.2" } assertj-assertjGuava = { group = "org.assertj", name = "assertj-guava", version = "3.24.2" } diff --git a/plugin/src/test/resources/expectations/assertj-bom/name-exclusion-test.toml b/plugin/src/test/resources/expectations/assertj-bom/name-exclusion-test.toml index 8e3a4a5..2af68b2 100644 --- a/plugin/src/test/resources/expectations/assertj-bom/name-exclusion-test.toml +++ b/plugin/src/test/resources/expectations/assertj-bom/name-exclusion-test.toml @@ -1,6 +1,7 @@ [versions] [libraries] +assertj-assertjBom = { group = "org.assertj", name = "assertj-bom", version = "3.24.2" } assertj-assertjCore = { group = "org.assertj", name = "assertj-core", version = "3.24.2" } [bundles] diff --git a/plugin/src/test/resources/expectations/spring-boot-dependencies/libs.versions.toml b/plugin/src/test/resources/expectations/spring-boot-dependencies/libs.versions.toml index dd1b617..72a39d0 100644 --- a/plugin/src/test/resources/expectations/spring-boot-dependencies/libs.versions.toml +++ b/plugin/src/test/resources/expectations/spring-boot-dependencies/libs.versions.toml @@ -21,6 +21,7 @@ awssdk-sqs = { group = "software.amazon.awssdk", name = "sqs", version = "2.21.2 awssdk-sts = { group = "software.amazon.awssdk", name = "sts", version = "2.21.21" } spring-springBoot = { group = "org.springframework.boot", name = "spring-boot", version = "3.1.2" } spring-springBootDevtools = { group = "org.springframework.boot", name = "spring-boot-devtools", version = "3.1.2" } +spring-springBootDependencies = { group = "org.springframework.boot", name = "spring-boot-dependencies", version = "3.1.2" } spring-springBootStarterActuator = { group = "org.springframework.boot", name = "spring-boot-starter-actuator", version = "3.1.2" } spring-springBootStarterAop = { group = "org.springframework.boot", name = "spring-boot-starter-aop", version = "3.1.2" } spring-springBootStarterJdbc = { group = "org.springframework.boot", name = "spring-boot-starter-jdbc", version = "3.1.2" } diff --git a/plugin/src/test/resources/expectations/spring-boot-dependencies/property-overrides.toml b/plugin/src/test/resources/expectations/spring-boot-dependencies/property-overrides.toml index 806d601..53745fe 100644 --- a/plugin/src/test/resources/expectations/spring-boot-dependencies/property-overrides.toml +++ b/plugin/src/test/resources/expectations/spring-boot-dependencies/property-overrides.toml @@ -20,6 +20,7 @@ awssdk-s3 = { group = "software.amazon.awssdk", name = "s3", version = "2.21.21" awssdk-sqs = { group = "software.amazon.awssdk", name = "sqs", version = "2.21.21" } awssdk-sts = { group = "software.amazon.awssdk", name = "sts", version = "2.21.21" } spring-springBoot = { group = "org.springframework.boot", name = "spring-boot", version = "3.1.2" } +spring-springBootDependencies = { group = "org.springframework.boot", name = "spring-boot-dependencies", version = "3.1.2" } spring-springBootDevtools = { group = "org.springframework.boot", name = "spring-boot-devtools", version = "3.1.2" } spring-springBootStarterActuator = { group = "org.springframework.boot", name = "spring-boot-starter-actuator", version = "3.1.2" } spring-springBootStarterAop = { group = "org.springframework.boot", name = "spring-boot-starter-aop", version = "3.1.2" } From 345e39c925940dcb04f9f20e4e31be7e89adfc18 Mon Sep 17 00:00:00 2001 From: Austin Arbor Date: Sun, 20 Oct 2024 17:26:42 -0400 Subject: [PATCH 2/3] disable fail-fast --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb6a25e..728647e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,6 +42,7 @@ jobs: include: - gradle-version: "wrapper" gradle-command: "./gradlew" + fail-fast: false steps: - uses: actions/checkout@v4 name: Checkout From e37bccec8f0dd818f54bf7850a2ef6c3b461a53d Mon Sep 17 00:00:00 2001 From: Austin Arbor Date: Sun, 20 Oct 2024 18:03:04 -0400 Subject: [PATCH 3/3] use detached configuration to work with gradle 8.11 --- .../service/PublishedArtifactResolver.kt | 13 +------------ .../service/MockGradleDependencyResolver.kt | 2 +- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/plugin/src/main/kotlin/dev/aga/gradle/versioncatalogs/service/PublishedArtifactResolver.kt b/plugin/src/main/kotlin/dev/aga/gradle/versioncatalogs/service/PublishedArtifactResolver.kt index 18b33bc..b7ebffb 100644 --- a/plugin/src/main/kotlin/dev/aga/gradle/versioncatalogs/service/PublishedArtifactResolver.kt +++ b/plugin/src/main/kotlin/dev/aga/gradle/versioncatalogs/service/PublishedArtifactResolver.kt @@ -2,7 +2,6 @@ package dev.aga.gradle.versioncatalogs.service import dev.aga.gradle.versioncatalogs.exception.ResolutionException import java.io.File -import java.util.concurrent.atomic.AtomicInteger import java.util.function.Supplier import org.apache.maven.model.Dependency import org.gradle.api.artifacts.Configuration @@ -44,13 +43,7 @@ class PublishedArtifactResolver( } private fun createConfiguration(): Configuration { - val config = - drs.configurationContainer.create( - "incomingConfiguration${configurationCount.incrementAndGet()}", - ) - - return config.apply { - resolutionStrategy.activateDependencyLocking() + return drs.configurationContainer.detachedConfiguration().apply { attributes { attribute( Category.CATEGORY_ATTRIBUTE, @@ -61,8 +54,4 @@ class PublishedArtifactResolver( isCanBeConsumed = false } } - - companion object { - private val configurationCount = AtomicInteger(0) - } } diff --git a/plugin/src/test/kotlin/dev/aga/gradle/versioncatalogs/service/MockGradleDependencyResolver.kt b/plugin/src/test/kotlin/dev/aga/gradle/versioncatalogs/service/MockGradleDependencyResolver.kt index cacf65d..de44c8a 100644 --- a/plugin/src/test/kotlin/dev/aga/gradle/versioncatalogs/service/MockGradleDependencyResolver.kt +++ b/plugin/src/test/kotlin/dev/aga/gradle/versioncatalogs/service/MockGradleDependencyResolver.kt @@ -34,7 +34,7 @@ class MockGradleDependencyResolver(val rootDir: Path) : DependencyResolver { } private val configurationContainer = - mock { on { create(any()) } doReturn configuration } + mock { on { detachedConfiguration() } doReturn configuration } private val drs = mock {