-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate build steps to Gradle build (#46)
Currently, certain Gradle tasks (like 'build', 'check') don't work without running 'make generate' first. Instead of splitting logic in between Gradle and the Makefile, migrate logic for generating code, running license-header, and other details to the Gradle build so they can happen in the correct order automatically. This has the side effect that new users can use Gradle commands they are familiar with ('./gradlew build') and not have to learn the makefile conventions separately.
- Loading branch information
Showing
13 changed files
with
195 additions
and
77 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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import com.vanniktech.maven.publish.JavaLibrary | ||
import com.vanniktech.maven.publish.SonatypeHost | ||
import com.diffplug.gradle.spotless.SpotlessExtension | ||
import com.vanniktech.maven.publish.JavaLibrary | ||
import com.vanniktech.maven.publish.JavadocJar | ||
import com.vanniktech.maven.publish.SonatypeHost | ||
import net.ltgt.gradle.errorprone.CheckSeverity | ||
import net.ltgt.gradle.errorprone.errorprone | ||
|
||
|
@@ -18,9 +18,116 @@ java { | |
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
val bufCLIFile = project.layout.buildDirectory.file("gobin/buf").get().asFile | ||
val bufCLIPath: String = bufCLIFile.absolutePath | ||
val bufLicenseHeaderCLIFile = project.layout.buildDirectory.file("gobin/license-header").get().asFile | ||
val bufLicenseHeaderCLIPath: String = bufLicenseHeaderCLIFile.absolutePath | ||
|
||
tasks.register<Exec>("installBuf") { | ||
description = "Installs the Buf CLI." | ||
environment("GOBIN", bufCLIFile.parentFile.absolutePath) | ||
outputs.file(bufCLIFile) | ||
commandLine("go", "install", "github.com/bufbuild/buf/cmd/buf@latest") | ||
} | ||
|
||
tasks.register<Exec>("installLicenseHeader") { | ||
description = "Installs the Buf license-header CLI." | ||
environment("GOBIN", bufLicenseHeaderCLIFile.parentFile.absolutePath) | ||
outputs.file(bufLicenseHeaderCLIFile) | ||
commandLine("go", "install", "github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@latest") | ||
} | ||
|
||
tasks.register<Exec>("licenseHeader") { | ||
dependsOn("installLicenseHeader") | ||
description = "Runs the Buf license-header CLI." | ||
commandLine( | ||
bufLicenseHeaderCLIPath, | ||
"--license-type", | ||
"apache", | ||
"--copyright-holder", | ||
"Buf Technologies, Inc.", | ||
"--year-range", | ||
project.findProperty("license-header.years")!!.toString(), | ||
"--ignore", | ||
"src/main/java/build/buf/validate/", | ||
"--ignore", | ||
"conformance/src/main/java/build/buf/validate/conformance/", | ||
) | ||
} | ||
|
||
tasks.register<Exec>("generateTestSourcesImports") { | ||
dependsOn("installBuf") | ||
description = "Generates code with buf generate --include-imports for unit tests." | ||
commandLine( | ||
bufCLIPath, | ||
"generate", | ||
"--template", | ||
"src/test/resources/proto/buf.gen.imports.yaml", | ||
"src/test/resources/proto", | ||
"--include-imports", | ||
) | ||
} | ||
|
||
tasks.register<Exec>("generateTestSourcesNoImports") { | ||
dependsOn("installBuf") | ||
description = "Generates code with buf generate --include-imports for unit tests." | ||
commandLine(bufCLIPath, "generate", "--template", "src/test/resources/proto/buf.gen.noimports.yaml", "src/test/resources/proto") | ||
} | ||
|
||
tasks.register("generateTestSources") { | ||
dependsOn("generateTestSourcesImports", "generateTestSourcesNoImports") | ||
description = "Generates code with buf generate for unit tests" | ||
} | ||
|
||
tasks.register<Exec>("exportProtovalidateModule") { | ||
dependsOn("installBuf") | ||
description = "Exports the bufbuild/protovalidate module sources to src/main/resources." | ||
commandLine( | ||
bufCLIPath, | ||
"export", | ||
"buf.build/bufbuild/protovalidate:${project.findProperty("protovalidate.version")}", | ||
"--output", | ||
"src/main/resources", | ||
) | ||
} | ||
|
||
tasks.register<Exec>("generateSources") { | ||
dependsOn("installBuf") | ||
description = "Generates sources for the bufbuild/protovalidate module sources to src/main/java." | ||
commandLine(bufCLIPath, "generate", "--template", "buf.gen.yaml", "src/main/resources") | ||
} | ||
|
||
tasks.register<Exec>("generateConformance") { | ||
dependsOn("installBuf") | ||
description = "Generates sources for the bufbuild/protovalidate-testing module to conformance/src/main/java." | ||
commandLine( | ||
bufCLIPath, | ||
"generate", | ||
"--template", | ||
"conformance/buf.gen.yaml", | ||
"-o", | ||
"conformance/", | ||
"buf.build/bufbuild/protovalidate-testing:${project.findProperty("protovalidate.version")}", | ||
) | ||
} | ||
|
||
tasks.register("generate") { | ||
description = "Generates sources with buf generate and buf export." | ||
dependsOn( | ||
"generateTestSources", | ||
"exportProtovalidateModule", | ||
"generateSources", | ||
"generateConformance", | ||
"licenseHeader", | ||
) | ||
} | ||
|
||
tasks.withType<JavaCompile> { | ||
if (JavaVersion.current().isJava9Compatible) doFirst { | ||
options.compilerArgs = mutableListOf("--release", "8") | ||
dependsOn("generateTestSources") | ||
if (JavaVersion.current().isJava9Compatible) { | ||
doFirst { | ||
options.compilerArgs = mutableListOf("--release", "8") | ||
} | ||
} | ||
// Disable errorprone on generated code | ||
options.errorprone.excludedPaths.set("(.*/src/main/java/build/buf/validate/.*|.*/build/generated/.*)") | ||
|
@@ -60,7 +167,11 @@ sourceSets { | |
apply(plugin = "com.diffplug.spotless") | ||
configure<SpotlessExtension> { | ||
java { | ||
targetExclude("src/main/java/build/buf/validate/**/*.java") | ||
targetExclude("src/main/java/build/buf/validate/**/*.java", "build/generated/test-sources/bufgen/**/*.java") | ||
} | ||
kotlinGradle { | ||
ktlint() | ||
target("**/*.kts") | ||
} | ||
} | ||
|
||
|
@@ -94,28 +205,28 @@ mavenPublishing { | |
val releaseVersion = project.findProperty("releaseVersion") as String? ?: System.getenv("VERSION") | ||
coordinates("build.buf", "protovalidate", releaseVersion ?: "0.0.0-SNAPSHOT") | ||
pomFromGradleProperties() | ||
configure(JavaLibrary( | ||
configure( | ||
JavaLibrary( | ||
// configures the -javadoc artifact, possible values: | ||
// - `JavadocJar.None()` don't publish this artifact | ||
// - `JavadocJar.Empty()` publish an emprt jar | ||
// - `JavadocJar.Empty()` publish an empty jar | ||
// - `JavadocJar.Javadoc()` to publish standard javadocs | ||
javadocJar = JavadocJar.Javadoc(), | ||
// whether to publish a sources jar | ||
sourcesJar = true, | ||
) | ||
), | ||
) | ||
pom { | ||
name.set("connect-library") // This is overwritten in subprojects. | ||
name.set("protovalidate-java") | ||
group = "build.buf" | ||
val releaseVersion = project.findProperty("releaseVersion") as String? | ||
// Default to snapshot versioning for local publishing. | ||
version = releaseVersion ?: "0.0.0-SNAPSHOT" | ||
description.set("Protocol Buffer Validation") | ||
url.set("https://github.com/bufbuild/protovalidate-java") | ||
licenses { | ||
license { | ||
name.set("The Apache Software License, Version 2.0") | ||
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") | ||
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") | ||
distribution.set("repo") | ||
} | ||
} | ||
|
@@ -131,7 +242,6 @@ mavenPublishing { | |
developerConnection.set("scm:git:ssh://[email protected]/bufbuild/protovalidate-java.git") | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
|
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 was deleted.
Oops, something went wrong.
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
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,8 @@ | ||
# When updating, also update src/test/resources/proto/buf.yaml and re-run 'buf mod update'. | ||
protovalidate.version = v0.4.3 | ||
|
||
# Arguments to the protovalidate-conformance CLI | ||
protovalidate.conformance.args = --strict_message | ||
|
||
# Argument to the license-header CLI | ||
license-header.years = 2023 |
Binary file not shown.
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.