Add SBOM for gradle plugins

^KTI-1273
This commit is contained in:
Bogdan Mukvich
2023-06-07 17:24:46 +02:00
committed by Space Team
parent fba0bd79ad
commit acb97d8cc9
3 changed files with 20 additions and 11 deletions
+18 -9
View File
@@ -64,8 +64,10 @@ val commonSourceSetName = "common"
* Configures common pom configuration parameters * Configures common pom configuration parameters
*/ */
fun Project.configureCommonPublicationSettingsForGradle( fun Project.configureCommonPublicationSettingsForGradle(
signingRequired: Boolean signingRequired: Boolean,
sbom: Boolean = true,
) { ) {
val sbomTask = if (sbom) configureSbom() else null
plugins.withId("maven-publish") { plugins.withId("maven-publish") {
configureDefaultPublishing(signingRequired) configureDefaultPublishing(signingRequired)
@@ -74,6 +76,12 @@ fun Project.configureCommonPublicationSettingsForGradle(
.withType<MavenPublication>() .withType<MavenPublication>()
.configureEach { .configureEach {
configureKotlinPomAttributes(project) configureKotlinPomAttributes(project)
if (sbomTask != null) {
artifact(sbomTask.map { it.outputDirectory.file("MainPublication.spdx.json") }) {
extension = "spdx.json"
}
}
} }
} }
} }
@@ -168,7 +176,7 @@ fun Project.createGradleCommonSourceSet(): SourceSet {
*/ */
private fun Project.fixWiredSourceSetSecondaryVariants( private fun Project.fixWiredSourceSetSecondaryVariants(
wireSourceSet: SourceSet, wireSourceSet: SourceSet,
commonSourceSet: SourceSet commonSourceSet: SourceSet,
) { ) {
configurations configurations
.matching { .matching {
@@ -226,7 +234,7 @@ private fun Project.fixWiredSourceSetSecondaryVariants(
*/ */
fun Project.wireGradleVariantToCommonGradleVariant( fun Project.wireGradleVariantToCommonGradleVariant(
wireSourceSet: SourceSet, wireSourceSet: SourceSet,
commonSourceSet: SourceSet commonSourceSet: SourceSet,
) { ) {
wireSourceSet.compileClasspath += commonSourceSet.output wireSourceSet.compileClasspath += commonSourceSet.output
wireSourceSet.runtimeClasspath += commonSourceSet.output wireSourceSet.runtimeClasspath += commonSourceSet.output
@@ -269,7 +277,7 @@ private const val FIXED_CONFIGURATION_SUFFIX = "WithFixedAttribute"
* 'main' sources are used for minimal supported Gradle versions (6.7) up to Gradle 7.0. * 'main' sources are used for minimal supported Gradle versions (6.7) up to Gradle 7.0.
*/ */
fun Project.reconfigureMainSourcesSetForGradlePlugin( fun Project.reconfigureMainSourcesSetForGradlePlugin(
commonSourceSet: SourceSet commonSourceSet: SourceSet,
) { ) {
sourceSets.named(SourceSet.MAIN_SOURCE_SET_NAME) { sourceSets.named(SourceSet.MAIN_SOURCE_SET_NAME) {
plugins.withType<JavaGradlePluginPlugin>().configureEach { plugins.withType<JavaGradlePluginPlugin>().configureEach {
@@ -374,9 +382,10 @@ fun Project.reconfigureMainSourcesSetForGradlePlugin(
TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE
) )
if (attributes.keySet() != expectedAttributes) { if (attributes.keySet() != expectedAttributes) {
error("Wrong set of attributes:\n" + error(
" Expected: ${expectedAttributes.joinToString(", ")}\n" + "Wrong set of attributes:\n" +
" Actual: ${attributes.keySet().joinToString(", ") { "${it.name}=${attributes.getAttribute(it)}" }}" " Expected: ${expectedAttributes.joinToString(", ")}\n" +
" Actual: ${attributes.keySet().joinToString(", ") { "${it.name}=${attributes.getAttribute(it)}" }}"
) )
} }
@@ -418,7 +427,7 @@ fun Project.reconfigureMainSourcesSetForGradlePlugin(
fun Project.createGradlePluginVariant( fun Project.createGradlePluginVariant(
variant: GradlePluginVariant, variant: GradlePluginVariant,
commonSourceSet: SourceSet, commonSourceSet: SourceSet,
isGradlePlugin: Boolean = true isGradlePlugin: Boolean = true,
): SourceSet { ): SourceSet {
val variantSourceSet = sourceSets.create(variant.sourceSetName) { val variantSourceSet = sourceSets.create(variant.sourceSetName) {
excludeGradleCommonDependencies(this) excludeGradleCommonDependencies(this)
@@ -539,7 +548,7 @@ fun Project.configureKotlinCompileTasksGradleCompatibility() {
// Will allow combining outputs of multiple SourceSets // Will allow combining outputs of multiple SourceSets
fun Project.publishShadowedJar( fun Project.publishShadowedJar(
sourceSet: SourceSet, sourceSet: SourceSet,
commonSourceSet: SourceSet commonSourceSet: SourceSet,
) { ) {
val jarTask = tasks.named<Jar>(sourceSet.jarTaskName) val jarTask = tasks.named<Jar>(sourceSet.jarTaskName)
@@ -35,7 +35,7 @@ dependencies {
compileOnly project(':dependencies:intellij-core') compileOnly project(':dependencies:intellij-core')
} }
GradleCommonKt.configureCommonPublicationSettingsForGradle(project, false) GradleCommonKt.configureCommonPublicationSettingsForGradle(project, false, false)
GradleCommonKt.configureKotlinCompileTasksGradleCompatibility(project) GradleCommonKt.configureKotlinCompileTasksGradleCompatibility(project)
GradleCommonKt.excludeGradleCommonDependencies(project, sourceSets.main) GradleCommonKt.excludeGradleCommonDependencies(project, sourceSets.main)
TasksKt.optInToExperimentalCompilerApi(project) TasksKt.optInToExperimentalCompilerApi(project)
@@ -26,7 +26,7 @@ dependencies {
} }
} }
configureCommonPublicationSettingsForGradle(signLibraryPublication) configureCommonPublicationSettingsForGradle(signLibraryPublication, sbom = false)
publishing { publishing {
publications { publications {