-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move code to sigstore-java folder, and factor out build logic
Signed-off-by: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
- Loading branch information
Showing
30 changed files
with
485 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/*/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
group = "dev.sigstore.sigstore-gradle" | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
val kotlinDslVersion = PluginDependenciesSpec { id -> | ||
object : PluginDependencySpec { | ||
var version: String? = null | ||
override fun version(version: String?) = apply { this.version = version } | ||
override fun apply(apply: Boolean) = this | ||
override fun toString() = version ?: "" | ||
} | ||
}.`kotlin-dsl`.toString() | ||
|
||
dependencies { | ||
implementation("org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:$kotlinDslVersion") | ||
// implementation("org.gradle.kotlin:gradle-kotlin-dsl-conventions:0.7.0") | ||
} | ||
|
||
kotlinDslPluginOptions { | ||
experimentalWarning.set(false) | ||
} |
18 changes: 18 additions & 0 deletions
18
...gic-commons/gradle-plugin/src/main/kotlin/build-logic.kotlin-dsl-gradle-plugin.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
plugins { | ||
id("java-library") | ||
id("org.gradle.kotlin.kotlin-dsl") // this is 'kotlin-dsl' without version | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
|
||
tasks.validatePlugins { | ||
failOnWarning.set(true) | ||
enableStricterValidation.set(true) | ||
} | ||
|
||
kotlinDslPluginOptions { | ||
experimentalWarning.set(false) | ||
} |
22 changes: 22 additions & 0 deletions
22
...ogic-commons/gradle-plugin/src/main/kotlin/buildlogic/DependencyHandlerScopeExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package buildlogic | ||
|
||
import org.gradle.kotlin.dsl.DependencyHandlerScope | ||
import org.gradle.kotlin.dsl.`kotlin-dsl` | ||
import org.gradle.plugin.use.PluginDependenciesSpec | ||
import org.gradle.plugin.use.PluginDependencySpec | ||
|
||
val DependencyHandlerScope.kotlinDslVersion: String | ||
get() = PluginDependenciesSpec { | ||
object : PluginDependencySpec { | ||
var version: String? = null | ||
override fun version(version: String?) = apply { this.version = version } | ||
override fun apply(apply: Boolean) = this | ||
override fun toString() = version ?: "" | ||
} | ||
}.`kotlin-dsl`.toString() | ||
|
||
fun DependencyHandlerScope.plugin(id: String, version: String) = | ||
"$id:$id.gradle.plugin:$version" | ||
|
||
fun DependencyHandlerScope.embeddedKotlinDsl() = | ||
plugin("org.gradle.kotlin.kotlin-dsl", kotlinDslVersion) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
systemProp.org.gradle.kotlin.dsl.precompiled.accessors.strict=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
dependencyResolutionManagement { | ||
repositories { | ||
gradlePluginPortal() | ||
} | ||
} | ||
|
||
rootProject.name = "build-logic-commons" | ||
|
||
include("gradle-plugin") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/*/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Build logic for Sigstore Java | ||
|
||
This is a subset of extra plugins for factoring out | ||
the common patterns from the common build logic. | ||
|
||
The recommended approach is to use build composition, so every build script | ||
should list all its prerequisites in the top-most `plugins { ... }` block. | ||
|
||
The use of `allprojects` and `subprojects` is an anti-pattern as it makes it hard to identify | ||
the configuration for a given project. | ||
|
||
Let us consider an example (see `/sigstore-gradle-sign-base-plugin/build.gradle.kts`): | ||
|
||
```kotlin | ||
plugins { | ||
id("build-logic.kotlin-dsl-published-gradle-plugin") | ||
id("build-logic.test-junit5") | ||
} | ||
|
||
description = "Gradle plugin with the base set of tasks and configurations for Sigstore singing (no signing is done by default)" | ||
|
||
dependencies { | ||
compileOnly(project(":sigstore-java")) | ||
implementation("com.fasterxml.jackson.core:jackson-databind:2.13.3") | ||
|
||
testImplementation(project(":sigstore-testkit")) | ||
} | ||
``` | ||
|
||
It means that we deal with a Gradle plugin written in Kotlin that will be published to Central, | ||
and which uses JUnit 5 for testing. | ||
|
||
If you want to see what the logic does, you could open `buildlogic.kotlin-dsl-published-plugin.gradle.kts` | ||
and `buildlogic.test-junit5.gradle.kts`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
plugins { | ||
id("build-logic.kotlin-dsl-gradle-plugin") | ||
} |
3 changes: 3 additions & 0 deletions
3
build-logic/basics/src/main/kotlin/build-logic.repositories.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
repositories { | ||
mavenCentral() | ||
} |
7 changes: 7 additions & 0 deletions
7
build-logic/basics/src/main/kotlin/build-logic.reproducible-builds.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
tasks.withType<AbstractArchiveTask>().configureEach { | ||
// Ensure builds are reproducible | ||
isPreserveFileTimestamps = false | ||
isReproducibleFileOrder = true | ||
dirMode = "775".toInt(8) | ||
fileMode = "664".toInt(8) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
systemProp.org.gradle.kotlin.dsl.precompiled.accessors.strict=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import buildlogic.embeddedKotlinDsl | ||
import buildlogic.plugin | ||
|
||
plugins { | ||
id("build-logic.kotlin-dsl-gradle-plugin") | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
implementation(embeddedKotlinDsl()) | ||
implementation(plugin("com.github.vlsi.gradle-extensions", "1.82")) | ||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin") | ||
} |
4 changes: 4 additions & 0 deletions
4
build-logic/jvm/src/main/kotlin/build-logic.java-library.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
plugins { | ||
id("build-logic.java") | ||
id("java-library") | ||
} |
48 changes: 48 additions & 0 deletions
48
build-logic/jvm/src/main/kotlin/build-logic.java.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import buildlogic.filterEolSimple | ||
|
||
plugins { | ||
`java-base` | ||
id("com.github.vlsi.gradle-extensions") | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
|
||
tasks.withType<JavaCompile>().configureEach { | ||
inputs.property("java.version", System.getProperty("java.version")) | ||
inputs.property("java.vm.version", System.getProperty("java.vm.version")) | ||
options.apply { | ||
encoding = "UTF-8" | ||
compilerArgs.add("-Xlint:deprecation") | ||
compilerArgs.add("-Werror") | ||
} | ||
} | ||
|
||
tasks.withType<Javadoc>().configureEach { | ||
(options as StandardJavadocDocletOptions).apply { | ||
addBooleanOption("Xwerror", true) | ||
addStringOption("sourcepath", "src/main/java") | ||
// intentionally ignore missing errors for now | ||
addBooleanOption("Xdoclint:all,-missing", true) | ||
} | ||
} | ||
|
||
// Add default license/notice when missing (e.g. see :src:config that overrides LICENSE) | ||
|
||
tasks.withType<Jar>().configureEach { | ||
into("META-INF") { | ||
filterEolSimple("crlf") | ||
from("$rootDir/LICENSE") | ||
from("$rootDir/NOTICE") | ||
} | ||
manifest { | ||
attributes["Bundle-License"] = "Apache-2.0" | ||
attributes["Specification-Title"] = project.name + " " + project.description | ||
attributes["Specification-Vendor"] = "dev.sigstore" | ||
attributes["Implementation-Vendor"] = "dev.sigstore" | ||
attributes["Implementation-Vendor-Id"] = "dev.sigstore" | ||
// Implementation-Version is not here to make jar reproducible across versions | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
build-logic/jvm/src/main/kotlin/build-logic.test-junit5.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies { | ||
testImplementation("org.junit.jupiter:junit-jupiter") | ||
testImplementation("org.assertj:assertj-core") | ||
} | ||
|
||
tasks.withType<Test>().configureEach { | ||
useJUnitPlatform() | ||
} |
16 changes: 16 additions & 0 deletions
16
build-logic/jvm/src/main/kotlin/buildlogic/CopySpecExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package buildlogic | ||
|
||
import org.apache.tools.ant.filters.FixCrLfFilter | ||
import org.gradle.api.file.CopySpec | ||
import org.gradle.kotlin.dsl.filter | ||
|
||
fun CopySpec.filterEolSimple(eol: String) { | ||
filteringCharset = "UTF-8" | ||
filter( | ||
FixCrLfFilter::class, mapOf( | ||
"eol" to FixCrLfFilter.CrLf.newInstance(eol), | ||
"fixlast" to true, | ||
"ctrlz" to FixCrLfFilter.AddAsisRemove.newInstance("asis") | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import buildlogic.plugin | ||
|
||
plugins { | ||
id("build-logic.kotlin-dsl-gradle-plugin") | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
implementation(project(":basics")) | ||
implementation(project(":jvm")) | ||
implementation("dev.sigstore.sigstore-gradle:gradle-plugin") | ||
implementation(plugin("com.gradle.plugin-publish", "0.14.0")) | ||
implementation(plugin("io.github.gradle-nexus.publish-plugin", "1.1.0")) | ||
} |
19 changes: 19 additions & 0 deletions
19
build-logic/publishing/src/main/kotlin/build-logic.java-published-library.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
plugins { | ||
id("build-logic.repositories") | ||
id("build-logic.java-library") | ||
id("build-logic.reproducible-builds") | ||
id("build-logic.publish-to-central") | ||
} | ||
|
||
java { | ||
withJavadocJar() | ||
withSourcesJar() | ||
} | ||
|
||
publishing { | ||
publications { | ||
create<MavenPublication>("mavenJava") { | ||
from(components["java"]) | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
build-logic/publishing/src/main/kotlin/build-logic.publish-to-central.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import buildlogic.cleanupMavenPom | ||
import org.gradle.api.publish.internal.PublicationInternal | ||
|
||
plugins { | ||
id("java-library") | ||
id("maven-publish") | ||
} | ||
|
||
val repoUrl = "https://github.com/sigstore/sigstore-java" | ||
|
||
publishing { | ||
publications.withType<MavenPublication>().configureEach { | ||
// Use the resolved versions in pom.xml | ||
// Gradle might have different resolution rules, so we set the versions | ||
// that were used in Gradle build/test. | ||
versionMapping { | ||
usage(Usage.JAVA_RUNTIME) { | ||
fromResolutionResult() | ||
} | ||
usage(Usage.JAVA_API) { | ||
fromResolutionOf("runtimeClasspath") | ||
} | ||
} | ||
pom { | ||
cleanupMavenPom() | ||
name.set( | ||
(project.findProperty("artifact.name") as? String) | ||
?: project.name | ||
) | ||
// This code might be executed before project-related build.gradle.kts is evaluated | ||
// So we delay access to project.description | ||
description.set( | ||
project.provider { project.description } | ||
) | ||
inceptionYear.set("2022") | ||
url.set(repoUrl) | ||
organization { | ||
name.set("Sigstore") | ||
url.set("https://sigstore.dev") | ||
} | ||
developers { | ||
developer { | ||
organization.set("Sigstore authors") | ||
organizationUrl.set("https://sigstore.dev") | ||
} | ||
} | ||
issueManagement { | ||
system.set("GitHub Issues") | ||
url.set("$repoUrl/issues") | ||
} | ||
licenses { | ||
license { | ||
name.set("Apache-2.0") | ||
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") | ||
} | ||
} | ||
scm { | ||
connection.set("scm:git:$repoUrl.git") | ||
developerConnection.set("scm:git:$repoUrl.git") | ||
url.set(repoUrl) | ||
tag.set("HEAD") | ||
} | ||
} | ||
} | ||
} | ||
|
||
val createReleaseBundle by tasks.registering(Sync::class) { | ||
description = "This task should be used by github actions to create release artifacts along with a slsa attestation" | ||
val releaseDir = layout.buildDirectory.dir("release") | ||
outputs.dir(releaseDir) | ||
|
||
into(releaseDir) | ||
rename("pom-default.xml", "${project.name}-${project.version}.pom") | ||
rename("module.json", "${project.name}-${project.version}.module") | ||
} | ||
|
||
publishing { | ||
publications.configureEach { | ||
(this as PublicationInternal<*>).allPublishableArtifacts { | ||
val publicationArtifact = this | ||
createReleaseBundle.configure { | ||
dependsOn(publicationArtifact) | ||
from(publicationArtifact.file) | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.