Skip to content

Commit

Permalink
Use Gradle's task configuration avoidance APIs
Browse files Browse the repository at this point in the history
This can avoid creating an additional 736 tasks (previously 502 out of
1591 were not created). That's not all that important as the build time
is essentially the same, but this lets us see the poor behavior of the
protobuf plugin in our own project and increase our understanding of how
to avoid task creation when developing the plugin. Of the tasks still
being created, protobuf is the highest contributor with 165 tasks,
followed by maven-publish with 76 and appengine with 53. The remaining
59 are from our own build, but indirectly caused by maven-publish.
  • Loading branch information
ejona86 committed Jul 8, 2022
1 parent e767905 commit 0ff9f37
Show file tree
Hide file tree
Showing 28 changed files with 210 additions and 161 deletions.
8 changes: 4 additions & 4 deletions all/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
api subprojects.minus([project(':grpc-protobuf-lite')])
}

javadoc {
tasks.named("javadoc").configure {
classpath = files(subprojects.collect { subproject ->
subproject.javadoc.classpath
})
Expand All @@ -49,7 +49,7 @@ javadoc {
}
}

task jacocoMerge(type: JacocoMerge) {
tasks.register("jacocoMerge", JacocoMerge) {
dependsOn(subprojects.jacocoTestReport.dependsOn)
dependsOn(project(':grpc-interop-testing').jacocoTestReport.dependsOn)
mustRunAfter(subprojects.jacocoTestReport.mustRunAfter)
Expand All @@ -60,7 +60,7 @@ task jacocoMerge(type: JacocoMerge) {
.filter { f -> f.exists() }
}

jacocoTestReport {
tasks.named("jacocoTestReport").configure {
dependsOn(jacocoMerge)
reports {
xml.required = true
Expand All @@ -78,4 +78,4 @@ coveralls {
sourceDirs = subprojects.sourceSets.main.allSource.srcDirs.flatten()
}

tasks.coveralls { dependsOn(jacocoTestReport) }
tasks.named("coveralls").configure { dependsOn tasks.named("jacocoTestReport") }
12 changes: 6 additions & 6 deletions alts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,28 @@ configureProtoCompilation()

import net.ltgt.gradle.errorprone.CheckSeverity

[compileJava, compileTestJava].each() {
[tasks.named("compileJava"), tasks.named("compileTestJava")]*.configure {
// protobuf calls valueof. Will be fixed in next release (google/protobuf#4046)
it.options.compilerArgs += [
options.compilerArgs += [
"-Xlint:-deprecation"
]
// ALTS returns a lot of futures that we mostly don't care about.
it.options.errorprone.check("FutureReturnValueIgnored", CheckSeverity.OFF)
options.errorprone.check("FutureReturnValueIgnored", CheckSeverity.OFF)
}

javadoc {
tasks.named("javadoc").configure {
exclude 'io/grpc/alts/internal/**'
exclude 'io/grpc/alts/Internal*'
}

jar {
tasks.named("jar").configure {
// Must use a different archiveClassifier to avoid conflicting with shadowJar
archiveClassifier = 'original'
}

// We want to use grpc-netty-shaded instead of grpc-netty. But we also want our
// source to work with Bazel, so we rewrite the code as part of the build.
shadowJar {
tasks.named("shadowJar").configure {
archiveClassifier = null
dependencies {
exclude(dependency {true})
Expand Down
2 changes: 1 addition & 1 deletion android-interop-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ project.tasks['check'].dependsOn checkStyleMain, checkStyleTest

import net.ltgt.gradle.errorprone.CheckSeverity

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.compilerArgs += [
"-Xlint:-cast"
]
Expand Down
7 changes: 4 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies {
testImplementation libraries.truth
}

task javadocs(type: Javadoc) {
tasks.register("javadocs", Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.getBootClasspath())
classpath += files({
Expand All @@ -58,12 +58,13 @@ task javadocs(type: Javadoc) {
}
}

task javadocJar(type: Jar, dependsOn: javadocs) {
tasks.register("javadocJar", Jar) {
dependsOn javadocs
archiveClassifier = 'javadoc'
from javadocs.destinationDir
}

task sourcesJar(type: Jar) {
tasks.register("sourcesJar", Jar) {
archiveClassifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
Expand Down
2 changes: 1 addition & 1 deletion api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature"
}

javadoc {
tasks.named("javadoc").configure {
// We want io.grpc.Internal, but not io.grpc.Internal*
exclude 'io/grpc/Internal?*.java'
}
10 changes: 6 additions & 4 deletions authz/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ dependencies {
signature "org.codehaus.mojo.signature:java17:1.0@signature"
}

jar {
tasks.named("jar").configure {
classifier = 'original'
}

// TODO(ashithasantosh): Remove javadoc exclusion on adding authorization
// interceptor implementations.
javadoc {
tasks.named("javadoc").configure {
exclude "io/grpc/authz/*"
}

shadowJar {
tasks.named("shadowJar").configure {
classifier = null
dependencies {
exclude(dependency {true})
Expand Down Expand Up @@ -74,4 +74,6 @@ publishing {
}
}

publishMavenPublicationToMavenRepository.enabled = false
tasks.named("publishMavenPublicationToMavenRepository").configure {
enabled = false
}
23 changes: 14 additions & 9 deletions benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ plugins {

description = "grpc Benchmarks"

startScripts.enabled = false
run.enabled = false

jmh {
tasks.named("jmh").configure {
jvmArgs = ["-server", "-Xms2g", "-Xmx2g"]
}

Expand Down Expand Up @@ -46,7 +43,7 @@ dependencies {

import net.ltgt.gradle.errorprone.CheckSeverity

compileJava {
tasks.named("compileJava").configure {
// The Control.Void protobuf clashes
options.errorprone.check("JavaLangClash", CheckSeverity.OFF)
}
Expand All @@ -60,30 +57,38 @@ def vmArgs = [
"-XX:+PrintGCDetails"
]

task qps_client(type: CreateStartScripts) {
tasks.named("startScripts").configure {
enabled = false
}

tasks.named("run").configure {
enabled = false
}

def qps_client = tasks.register("qps_client", CreateStartScripts) {
mainClass = "io.grpc.benchmarks.qps.AsyncClient"
applicationName = "qps_client"
defaultJvmOpts = vmArgs
outputDir = new File(project.buildDir, 'tmp/scripts/' + name)
classpath = startScripts.classpath
}

task openloop_client(type: CreateStartScripts) {
def openloop_client = tasks.register("openloop_client", CreateStartScripts) {
mainClass = "io.grpc.benchmarks.qps.OpenLoopClient"
applicationName = "openloop_client"
defaultJvmOpts = vmArgs
outputDir = new File(project.buildDir, 'tmp/scripts/' + name)
classpath = startScripts.classpath
}

task qps_server(type: CreateStartScripts) {
def qps_server = tasks.register("qps_server", CreateStartScripts) {
mainClass = "io.grpc.benchmarks.qps.AsyncServer"
applicationName = "qps_server"
outputDir = new File(project.buildDir, 'tmp/scripts/' + name)
classpath = startScripts.classpath
}

task benchmark_worker(type: CreateStartScripts) {
def benchmark_worker = tasks.register("benchmark_worker", CreateStartScripts) {
mainClass = "io.grpc.benchmarks.driver.LoadWorker"
applicationName = "benchmark_worker"
defaultJvmOpts = vmArgs
Expand Down
9 changes: 5 additions & 4 deletions binder/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ dependencies {

import net.ltgt.gradle.errorprone.CheckSeverity

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.compilerArgs += [
"-Xlint:-cast"
]
Expand All @@ -94,7 +94,7 @@ tasks.withType(JavaCompile) {
options.errorprone.check("UnnecessaryAnonymousClass", CheckSeverity.OFF)
}

task javadocs(type: Javadoc) {
tasks.register("javadocs", Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.getBootClasspath())
classpath += files({
Expand All @@ -110,12 +110,13 @@ task javadocs(type: Javadoc) {
}
}

task javadocJar(type: Jar, dependsOn: javadocs) {
tasks.register("javadocJar", Jar) {
dependsOn javadocs
archiveClassifier = 'javadoc'
from javadocs.destinationDir
}

task sourcesJar(type: Jar) {
tasks.register("sourcesJar", Jar) {
archiveClassifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
Expand Down
Loading

0 comments on commit 0ff9f37

Please sign in to comment.