Skip to content

Commit

Permalink
Merge pull request #155 from austinarbor/generate-bom-entry
Browse files Browse the repository at this point in the history
Generate BOM Entry
  • Loading branch information
austinarbor authored Oct 20, 2024
2 parents c371298 + 5d66f96 commit 2550fa0
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
include:
- gradle-version: "wrapper"
gradle-command: "./gradlew"
fail-fast: false
steps:
- uses: actions/checkout@v4
name: Checkout
Expand Down
6 changes: 4 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ dependencyResolutionManagement {
"jackson-bom.version" to "2.16.1", // <4>
"mockito.version" to versionRef("mockito"), // <5>
)
generateBomEntry = true // <6>
}
generate("awsLibs") {
from(toml("awsBom"))
aliasPrefixGenerator = GeneratorConfig.NO_PREFIX // <6>
aliasPrefixGenerator = GeneratorConfig.NO_PREFIX // <7>
}
}
}
Expand All @@ -76,7 +77,8 @@ dependencyResolutionManagement {
<3> The name of the bom library in the version catalog
<4> Optionally override some version properties using a literal value
<5> Or, you can reference version aliases in the source TOML
<6> All dependencies in the AWS BOM are for AWS so we can skip the prefix
<6> Optionally generate an entry in the catalog for the BOM itself
<7> All dependencies in the AWS BOM are for AWS so we can skip the prefix
====

_Lastly, use the dependencies in your build_
Expand Down
1 change: 1 addition & 0 deletions plugin/src/docs/asciidoc/detailed-usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
== Detailed Usage
include::{docdir}/detailed-usage/applying.adoc[]
include::{docdir}/detailed-usage/sources.adoc[]
include::{docdir}/detailed-usage/bom-entry.adoc[]
include::{docdir}/detailed-usage/naming.adoc[]
include::{docdir}/detailed-usage/overrides.adoc[]
include::{docdir}/detailed-usage/filtering.adoc[]
Expand Down
28 changes: 28 additions & 0 deletions plugin/src/docs/asciidoc/detailed-usage/bom-entry.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

=== Including a BOM Entry

Optionally, you can configure the generator to also generate an entry in the catalog for the BOM itself.

.settings.gradle.kts
[source,kotlin,subs="attributes+",role="primary"]
----
generate("springLibs") {
from(toml("springBootDependencies"))
generateBomEntry = true // <1>
}
----
<1> Set `generateBomEntry` to `true` to include an entry for the BOM in the generated catalog

.settings.gradle
[source,groovy,subs="attributes+",role="secondary"]
----
generator.generate("springLibs") {
it.from { from ->
from.toml { toml ->
toml.libraryAlias = "springBootDependencies"
}
}
it.generateBomEntry = true // <1>
}
----
<1> Set `generateBomEntry` to `true` to include an entry for the BOM in the generated catalog
10 changes: 10 additions & 0 deletions plugin/src/main/kotlin/dev/aga/gradle/versioncatalogs/Generator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ internal class GeneratorTest {
}
cacheDirectory = projectDir
cacheEnabled = true
generateBomEntry = true
}

val resolver = MockGradleDependencyResolver(resourceRoot.resolve("poms"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class VersionCatalogGeneratorPluginTest {
GeneratorConfig.caseChange(artifact, net.pearx.kasechange.CaseFormat.LOWER_HYPHEN, net.pearx.kasechange.CaseFormat.LOWER_UNDERSCORE)
}
cacheEnabled = true
generateBomEntry = true
}
generate("awsLibs") {
from(toml("aws-bom"))
Expand Down Expand Up @@ -177,6 +178,7 @@ class VersionCatalogGeneratorPluginTest {
DEFAULT_ALIAS_GENERATOR.invoke(prefix,suffix)
}
it.versionNameGenerator = DEFAULT_VERSION_NAME_GENERATOR
it.generateBomEntry = true
}
generator.generate("junitLibs") {
it.from { from ->
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[versions]

[libraries]
assertj-assertjBom = { group = "org.assertj", name = "assertj-bom", version = "3.24.2" }

[bundles]
Original file line number Diff line number Diff line change
@@ -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" }

Expand Down
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down

0 comments on commit 2550fa0

Please sign in to comment.