-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from vlsi/add_buildlogic
Add build-logic to make adding new modules easier
- Loading branch information
Showing
180 changed files
with
551 additions
and
222 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,33 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
group = "dev.sigstore.build-logic" | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_11 | ||
targetCompatibility = JavaVersion.VERSION_11 | ||
} | ||
|
||
// We use precompiled script plugins (== plugins written as src/kotlin/build-logic.*.gradle.kts files, | ||
// and we need to declare dependency on org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin | ||
// to make it work. | ||
// Unfortunately, Gradle does not expose the version of `kotlin-dsl` in-core plugin, so we call `kotlin-dsl` | ||
// on our own PluginDependenciesSpec object, so it leaks the version to us. | ||
// See https://github.com/gradle/gradle/issues/17016 | ||
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") | ||
} | ||
|
||
kotlinDslPluginOptions { | ||
jvmTarget.set("11") | ||
} |
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 { | ||
jvmTarget.set("11") | ||
} |
19 changes: 19 additions & 0 deletions
19
...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,19 @@ | ||
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.embeddedKotlinDsl() = | ||
"org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:$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,15 @@ | ||
import buildlogic.embeddedKotlinDsl | ||
|
||
plugins { | ||
id("build-logic.kotlin-dsl-gradle-plugin") | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
implementation(embeddedKotlinDsl()) | ||
implementation("com.github.vlsi.gradle-extensions:com.github.vlsi.gradle-extensions.gradle.plugin: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() | ||
} |
21 changes: 21 additions & 0 deletions
21
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,21 @@ | ||
package buildlogic | ||
|
||
import org.apache.tools.ant.filters.FixCrLfFilter | ||
import org.gradle.api.file.CopySpec | ||
import org.gradle.kotlin.dsl.filter | ||
|
||
/** | ||
* Converts end-of-line markers in the current [CopySpec] to the given value. | ||
* See [org.apache.tools.ant.filters.FixCrLfFilter.CrLf] for the possible values of `eol`. | ||
* See https://github.com/gradle/gradle/issues/8688. | ||
*/ | ||
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,13 @@ | ||
plugins { | ||
id("build-logic.kotlin-dsl-gradle-plugin") | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
implementation(project(":basics")) | ||
implementation(project(":jvm")) | ||
implementation("com.gradle.plugin-publish:com.gradle.plugin-publish.gradle.plugin:1.0.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"]) | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
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,86 @@ | ||
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 { | ||
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) | ||
} | ||
} | ||
} | ||
} | ||
|
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") | ||
} |
File renamed without changes.
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,13 @@ | ||
dependencyResolutionManagement { | ||
repositories { | ||
gradlePluginPortal() | ||
} | ||
} | ||
|
||
rootProject.name = "build-logic" | ||
|
||
includeBuild("../build-logic-commons") | ||
include("basics") | ||
include("jvm") | ||
include("publishing") | ||
include("root-build") |
Oops, something went wrong.