Do not publish SBOM artifact by default
* In case we generate several artifacts like in kotlin-compiler there are separate jar and zip modules which differ in content
This commit is contained in:
committed by
Space Team
parent
bbe5418a85
commit
303f7493cc
@@ -1,15 +1,9 @@
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.publish.PublishingExtension
|
||||
import org.gradle.api.publish.maven.MavenPublication
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.tasks.Copy
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.findByType
|
||||
|
||||
import org.spdx.sbom.gradle.SpdxSbomExtension
|
||||
import org.spdx.sbom.gradle.SpdxSbomPlugin
|
||||
import plugins.mainPublicationName
|
||||
import java.util.*
|
||||
|
||||
/*
|
||||
@@ -17,12 +11,15 @@ import java.util.*
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
fun Project.configureSbom(gradleConfigurations: Iterable<String> = setOf("runtimeClasspath")): Configuration {
|
||||
fun Project.configureSbom(
|
||||
moduleName: String = this.name,
|
||||
gradleConfigurations: Iterable<String> = setOf("runtimeClasspath"),
|
||||
): Configuration {
|
||||
val project = this
|
||||
apply<SpdxSbomPlugin>()
|
||||
|
||||
configure<SpdxSbomExtension> {
|
||||
targets.create(project.name) {
|
||||
targets.create(moduleName) {
|
||||
configurations.set(gradleConfigurations)
|
||||
scm {
|
||||
tool.set("git")
|
||||
@@ -32,7 +29,7 @@ fun Project.configureSbom(gradleConfigurations: Iterable<String> = setOf("runtim
|
||||
|
||||
// adjust properties of the document
|
||||
document {
|
||||
name.set("SpdxDoc for ${project.name}")
|
||||
this.name.set("SpdxDoc for $moduleName")
|
||||
// NOTE: The URI does not have to be accessible. It is only intended to provide a unique ID.
|
||||
// In many cases, the URI will point to a Web accessible document, but this should not be assumed to be the case.
|
||||
namespace.set("https://www.jetbrains.com/spdxdocs/${UUID.randomUUID()}")
|
||||
@@ -42,27 +39,17 @@ fun Project.configureSbom(gradleConfigurations: Iterable<String> = setOf("runtim
|
||||
}
|
||||
}
|
||||
|
||||
val sbomCfg = configurations.maybeCreate("sbom").apply {
|
||||
val sbomCfg = configurations.maybeCreate("sbomFor$moduleName").apply {
|
||||
isCanBeResolved = false
|
||||
isCanBeConsumed = true
|
||||
}
|
||||
val sbomFile = layout.buildDirectory.file("spdx/${project.name}.spdx.json")
|
||||
val sbomArtifact = artifacts.add(sbomCfg.name, sbomFile.get().asFile) {
|
||||
val sbomFile = layout.buildDirectory.file("spdx/$moduleName.spdx.json")
|
||||
artifacts.add(sbomCfg.name, sbomFile.get().asFile) {
|
||||
type = "sbom"
|
||||
extension = "spdx.json"
|
||||
builtBy("spdxSbom")
|
||||
}
|
||||
val publication = extensions.findByType<PublishingExtension>()
|
||||
?.publications
|
||||
?.findByName(mainPublicationName) as MavenPublication?
|
||||
publication?.apply {
|
||||
artifact(sbomArtifact)
|
||||
val capitalizedModuleName =
|
||||
moduleName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
|
||||
builtBy("spdxSbomFor$capitalizedModuleName")
|
||||
}
|
||||
return sbomCfg
|
||||
}
|
||||
|
||||
fun Copy.fromSbom(sbom: Configuration) {
|
||||
from(sbom.artifacts.files) {
|
||||
rename("${project.name}.spdx.json", "${project.name}-${project.version}.spdx.json")
|
||||
}
|
||||
}
|
||||
@@ -395,7 +395,11 @@ val distJs = distTask<Sync>("distJs") {
|
||||
from(distJSContents)
|
||||
}
|
||||
|
||||
val sbom = configureSbom(setOf("runtimeClasspath", libraries.name, librariesStripVersion.name, compilerPlugins.name))
|
||||
val compilerZipSbomName = "kotlin-compiler-zip"
|
||||
val compilerZipSbom = configureSbom(
|
||||
moduleName = compilerZipSbomName,
|
||||
gradleConfigurations = setOf("runtimeClasspath", libraries.name, librariesStripVersion.name, compilerPlugins.name)
|
||||
)
|
||||
|
||||
distTask<Copy>("dist") {
|
||||
destinationDir = File(distDir)
|
||||
@@ -407,7 +411,9 @@ distTask<Copy>("dist") {
|
||||
|
||||
from(buildNumber)
|
||||
from(distStdlibMinimalForTests)
|
||||
fromSbom(sbom)
|
||||
from(compilerZipSbom.artifacts.files) {
|
||||
rename("$compilerZipSbomName.spdx.json", "${project.name}-${project.version}.spdx.json")
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : AbstractCopyTask> Project.distTask(
|
||||
|
||||
Reference in New Issue
Block a user