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
*/
fun Project.configureCommonPublicationSettingsForGradle(
signingRequired: Boolean
signingRequired: Boolean,
sbom: Boolean = true,
) {
val sbomTask = if (sbom) configureSbom() else null
plugins.withId("maven-publish") {
configureDefaultPublishing(signingRequired)
@@ -74,6 +76,12 @@ fun Project.configureCommonPublicationSettingsForGradle(
.withType<MavenPublication>()
.configureEach {
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(
wireSourceSet: SourceSet,
commonSourceSet: SourceSet
commonSourceSet: SourceSet,
) {
configurations
.matching {
@@ -226,7 +234,7 @@ private fun Project.fixWiredSourceSetSecondaryVariants(
*/
fun Project.wireGradleVariantToCommonGradleVariant(
wireSourceSet: SourceSet,
commonSourceSet: SourceSet
commonSourceSet: SourceSet,
) {
wireSourceSet.compileClasspath += 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.
*/
fun Project.reconfigureMainSourcesSetForGradlePlugin(
commonSourceSet: SourceSet
commonSourceSet: SourceSet,
) {
sourceSets.named(SourceSet.MAIN_SOURCE_SET_NAME) {
plugins.withType<JavaGradlePluginPlugin>().configureEach {
@@ -374,9 +382,10 @@ fun Project.reconfigureMainSourcesSetForGradlePlugin(
TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE
)
if (attributes.keySet() != expectedAttributes) {
error("Wrong set of attributes:\n" +
" Expected: ${expectedAttributes.joinToString(", ")}\n" +
" Actual: ${attributes.keySet().joinToString(", ") { "${it.name}=${attributes.getAttribute(it)}" }}"
error(
"Wrong set of attributes:\n" +
" Expected: ${expectedAttributes.joinToString(", ")}\n" +
" Actual: ${attributes.keySet().joinToString(", ") { "${it.name}=${attributes.getAttribute(it)}" }}"
)
}
@@ -418,7 +427,7 @@ fun Project.reconfigureMainSourcesSetForGradlePlugin(
fun Project.createGradlePluginVariant(
variant: GradlePluginVariant,
commonSourceSet: SourceSet,
isGradlePlugin: Boolean = true
isGradlePlugin: Boolean = true,
): SourceSet {
val variantSourceSet = sourceSets.create(variant.sourceSetName) {
excludeGradleCommonDependencies(this)
@@ -539,7 +548,7 @@ fun Project.configureKotlinCompileTasksGradleCompatibility() {
// Will allow combining outputs of multiple SourceSets
fun Project.publishShadowedJar(
sourceSet: SourceSet,
commonSourceSet: SourceSet
commonSourceSet: SourceSet,
) {
val jarTask = tasks.named<Jar>(sourceSet.jarTaskName)
@@ -35,7 +35,7 @@ dependencies {
compileOnly project(':dependencies:intellij-core')
}
GradleCommonKt.configureCommonPublicationSettingsForGradle(project, false)
GradleCommonKt.configureCommonPublicationSettingsForGradle(project, false, false)
GradleCommonKt.configureKotlinCompileTasksGradleCompatibility(project)
GradleCommonKt.excludeGradleCommonDependencies(project, sourceSets.main)
TasksKt.optInToExperimentalCompilerApi(project)
@@ -26,7 +26,7 @@ dependencies {
}
}
configureCommonPublicationSettingsForGradle(signLibraryPublication)
configureCommonPublicationSettingsForGradle(signLibraryPublication, sbom = false)
publishing {
publications {