Skip to content

Commit 0ff9f37

Browse files
committed
Use Gradle's task configuration avoidance APIs
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.
1 parent e767905 commit 0ff9f37

File tree

28 files changed

+210
-161
lines changed

28 files changed

+210
-161
lines changed

all/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies {
3636
api subprojects.minus([project(':grpc-protobuf-lite')])
3737
}
3838

39-
javadoc {
39+
tasks.named("javadoc").configure {
4040
classpath = files(subprojects.collect { subproject ->
4141
subproject.javadoc.classpath
4242
})
@@ -49,7 +49,7 @@ javadoc {
4949
}
5050
}
5151

52-
task jacocoMerge(type: JacocoMerge) {
52+
tasks.register("jacocoMerge", JacocoMerge) {
5353
dependsOn(subprojects.jacocoTestReport.dependsOn)
5454
dependsOn(project(':grpc-interop-testing').jacocoTestReport.dependsOn)
5555
mustRunAfter(subprojects.jacocoTestReport.mustRunAfter)
@@ -60,7 +60,7 @@ task jacocoMerge(type: JacocoMerge) {
6060
.filter { f -> f.exists() }
6161
}
6262

63-
jacocoTestReport {
63+
tasks.named("jacocoTestReport").configure {
6464
dependsOn(jacocoMerge)
6565
reports {
6666
xml.required = true
@@ -78,4 +78,4 @@ coveralls {
7878
sourceDirs = subprojects.sourceSets.main.allSource.srcDirs.flatten()
7979
}
8080

81-
tasks.coveralls { dependsOn(jacocoTestReport) }
81+
tasks.named("coveralls").configure { dependsOn tasks.named("jacocoTestReport") }

alts/build.gradle

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,28 @@ configureProtoCompilation()
5252

5353
import net.ltgt.gradle.errorprone.CheckSeverity
5454

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

64-
javadoc {
64+
tasks.named("javadoc").configure {
6565
exclude 'io/grpc/alts/internal/**'
6666
exclude 'io/grpc/alts/Internal*'
6767
}
6868

69-
jar {
69+
tasks.named("jar").configure {
7070
// Must use a different archiveClassifier to avoid conflicting with shadowJar
7171
archiveClassifier = 'original'
7272
}
7373

7474
// We want to use grpc-netty-shaded instead of grpc-netty. But we also want our
7575
// source to work with Bazel, so we rewrite the code as part of the build.
76-
shadowJar {
76+
tasks.named("shadowJar").configure {
7777
archiveClassifier = null
7878
dependencies {
7979
exclude(dependency {true})

android-interop-testing/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ project.tasks['check'].dependsOn checkStyleMain, checkStyleTest
101101

102102
import net.ltgt.gradle.errorprone.CheckSeverity
103103

104-
tasks.withType(JavaCompile) {
104+
tasks.withType(JavaCompile).configureEach {
105105
options.compilerArgs += [
106106
"-Xlint:-cast"
107107
]

android/build.gradle

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies {
4242
testImplementation libraries.truth
4343
}
4444

45-
task javadocs(type: Javadoc) {
45+
tasks.register("javadocs", Javadoc) {
4646
source = android.sourceSets.main.java.srcDirs
4747
classpath += files(android.getBootClasspath())
4848
classpath += files({
@@ -58,12 +58,13 @@ task javadocs(type: Javadoc) {
5858
}
5959
}
6060

61-
task javadocJar(type: Jar, dependsOn: javadocs) {
61+
tasks.register("javadocJar", Jar) {
62+
dependsOn javadocs
6263
archiveClassifier = 'javadoc'
6364
from javadocs.destinationDir
6465
}
6566

66-
task sourcesJar(type: Jar) {
67+
tasks.register("sourcesJar", Jar) {
6768
archiveClassifier = 'sources'
6869
from android.sourceSets.main.java.srcDirs
6970
}

api/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies {
2828
signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature"
2929
}
3030

31-
javadoc {
31+
tasks.named("javadoc").configure {
3232
// We want io.grpc.Internal, but not io.grpc.Internal*
3333
exclude 'io/grpc/Internal?*.java'
3434
}

authz/build.gradle

+6-4
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ dependencies {
2929
signature "org.codehaus.mojo.signature:java17:1.0@signature"
3030
}
3131

32-
jar {
32+
tasks.named("jar").configure {
3333
classifier = 'original'
3434
}
3535

3636
// TODO(ashithasantosh): Remove javadoc exclusion on adding authorization
3737
// interceptor implementations.
38-
javadoc {
38+
tasks.named("javadoc").configure {
3939
exclude "io/grpc/authz/*"
4040
}
4141

42-
shadowJar {
42+
tasks.named("shadowJar").configure {
4343
classifier = null
4444
dependencies {
4545
exclude(dependency {true})
@@ -74,4 +74,6 @@ publishing {
7474
}
7575
}
7676

77-
publishMavenPublicationToMavenRepository.enabled = false
77+
tasks.named("publishMavenPublicationToMavenRepository").configure {
78+
enabled = false
79+
}

benchmarks/build.gradle

+14-9
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ plugins {
99

1010
description = "grpc Benchmarks"
1111

12-
startScripts.enabled = false
13-
run.enabled = false
14-
15-
jmh {
12+
tasks.named("jmh").configure {
1613
jvmArgs = ["-server", "-Xms2g", "-Xmx2g"]
1714
}
1815

@@ -46,7 +43,7 @@ dependencies {
4643

4744
import net.ltgt.gradle.errorprone.CheckSeverity
4845

49-
compileJava {
46+
tasks.named("compileJava").configure {
5047
// The Control.Void protobuf clashes
5148
options.errorprone.check("JavaLangClash", CheckSeverity.OFF)
5249
}
@@ -60,30 +57,38 @@ def vmArgs = [
6057
"-XX:+PrintGCDetails"
6158
]
6259

63-
task qps_client(type: CreateStartScripts) {
60+
tasks.named("startScripts").configure {
61+
enabled = false
62+
}
63+
64+
tasks.named("run").configure {
65+
enabled = false
66+
}
67+
68+
def qps_client = tasks.register("qps_client", CreateStartScripts) {
6469
mainClass = "io.grpc.benchmarks.qps.AsyncClient"
6570
applicationName = "qps_client"
6671
defaultJvmOpts = vmArgs
6772
outputDir = new File(project.buildDir, 'tmp/scripts/' + name)
6873
classpath = startScripts.classpath
6974
}
7075

71-
task openloop_client(type: CreateStartScripts) {
76+
def openloop_client = tasks.register("openloop_client", CreateStartScripts) {
7277
mainClass = "io.grpc.benchmarks.qps.OpenLoopClient"
7378
applicationName = "openloop_client"
7479
defaultJvmOpts = vmArgs
7580
outputDir = new File(project.buildDir, 'tmp/scripts/' + name)
7681
classpath = startScripts.classpath
7782
}
7883

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

86-
task benchmark_worker(type: CreateStartScripts) {
91+
def benchmark_worker = tasks.register("benchmark_worker", CreateStartScripts) {
8792
mainClass = "io.grpc.benchmarks.driver.LoadWorker"
8893
applicationName = "benchmark_worker"
8994
defaultJvmOpts = vmArgs

binder/build.gradle

+5-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ dependencies {
8585

8686
import net.ltgt.gradle.errorprone.CheckSeverity
8787

88-
tasks.withType(JavaCompile) {
88+
tasks.withType(JavaCompile).configureEach {
8989
options.compilerArgs += [
9090
"-Xlint:-cast"
9191
]
@@ -94,7 +94,7 @@ tasks.withType(JavaCompile) {
9494
options.errorprone.check("UnnecessaryAnonymousClass", CheckSeverity.OFF)
9595
}
9696

97-
task javadocs(type: Javadoc) {
97+
tasks.register("javadocs", Javadoc) {
9898
source = android.sourceSets.main.java.srcDirs
9999
classpath += files(android.getBootClasspath())
100100
classpath += files({
@@ -110,12 +110,13 @@ task javadocs(type: Javadoc) {
110110
}
111111
}
112112

113-
task javadocJar(type: Jar, dependsOn: javadocs) {
113+
tasks.register("javadocJar", Jar) {
114+
dependsOn javadocs
114115
archiveClassifier = 'javadoc'
115116
from javadocs.destinationDir
116117
}
117118

118-
task sourcesJar(type: Jar) {
119+
tasks.register("sourcesJar", Jar) {
119120
archiveClassifier = 'sources'
120121
from android.sourceSets.main.java.srcDirs
121122
}

0 commit comments

Comments
 (0)