Skip to content

Commit 74d304f

Browse files
committed
fix: generate CycloneDX SBOM from root direct task
1 parent fdb24de commit 74d304f

3 files changed

Lines changed: 33 additions & 22 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@ jobs:
9191
--notes-file /tmp/CHANGELOG_RELEASE.md \
9292
build/distributions/*.zip \
9393
build/distributions/*.tar \
94-
build/reports/cyclonedx/bom.json
94+
build/reports/cyclonedx-direct/bom.json

build.gradle

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -247,32 +247,24 @@ dependencyCheck {
247247

248248
// ---------------------------------------------------------------------------
249249
// CycloneDX SBOM
250-
// The SBOM is generated only for the root project (the distribution artifact).
251-
// CycloneDX 3.x registers its tasks on every subproject in a multi-project
252-
// build, which conflicts with java-library's configuration consumption order.
253-
// Disabling the tasks in subprojects avoids that conflict while keeping the
254-
// root-level SBOM generation intact.
250+
// Represents the shipped MethodAtlas distribution, not the internal Gradle
251+
// module layout.
252+
//
253+
// The root distribution contains both CLI and GUI runtime material, therefore
254+
// both runtimeClasspath and guiRuntime are included.
255255
// ---------------------------------------------------------------------------
256-
cyclonedxBom {
257-
// includeConfigs was removed in 3.x; the task scans runtime configurations automatically.
256+
tasks.named('cyclonedxDirectBom') {
258257
schemaVersion = org.cyclonedx.Version.VERSION_15
259-
}
260258

261-
// Mark CycloneDX-owned configurations as non-consumable so that subprojects
262-
// which depend on project(':') (e.g. methodatlas-gui) do not resolve them
263-
// as variants. Without this, Gradle marks the configuration as "consumed"
264-
// before the CycloneDX plugin can add artifacts to it, which causes a
265-
// "Cannot mutate after consumed" error at task-graph construction time.
266-
configurations.all {
267-
if (name.startsWith('cyclonedx')) {
268-
canBeConsumed = false
269-
}
259+
includeConfigs = [
260+
"runtimeClasspath",
261+
"guiRuntime"
262+
]
270263
}
271264

272-
subprojects {
273-
tasks.matching { it.name.startsWith('cyclonedx') }.configureEach {
274-
enabled = false
275-
}
265+
// Prevent accidental use of the aggregate multi-project SBOM task.
266+
tasks.named('cyclonedxBom') {
267+
enabled = false
276268
}
277269

278270
// ---------------------------------------------------------------------------

settings.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,22 @@ include 'methodatlas-docs'
1313
// Build: ./gradlew :methodatlas-gui:build
1414
// Run: ./gradlew :methodatlas-gui:run
1515
include 'methodatlas-gui'
16+
17+
// ---------------------------------------------------------------------------
18+
// Compatibility rewrite:
19+
// Treat historical `./gradlew cyclonedxBom` as the MethodAtlas root
20+
// distribution SBOM task.
21+
// ---------------------------------------------------------------------------
22+
def requestedTaskNames = gradle.startParameter.taskNames
23+
24+
def rewrittenTaskNames = requestedTaskNames.collect { taskName ->
25+
if (taskName == 'cyclonedxBom' || taskName == ':cyclonedxBom') {
26+
return ':cyclonedxDirectBom'
27+
}
28+
return taskName
29+
}
30+
31+
if (rewrittenTaskNames != requestedTaskNames) {
32+
println "Redirecting cyclonedxBom to :cyclonedxDirectBom for the MethodAtlas unified distribution SBOM."
33+
gradle.startParameter.setTaskNames(rewrittenTaskNames)
34+
}

0 commit comments

Comments
 (0)