Use test fixtures instead of sourceSets.test.output

This avoids the (often missing) evaluationDependsOn and fixes using
results from other projects without propagating those through
Configuration. It also reduces the number of useless classes pulled in
by down-stream tests, reducing the probability of rebuilds.

The expectation of fixtures is they help testing down-stream code that
use the classes in main. That applies to all the classes here except for
FakeClock and StaticTestingClassLoader. It would also apply to many
internal classes in grpc-testing, but let's consider cleaning that up
future work.
This commit is contained in:
Eric Anderson 2023-05-16 12:10:13 -07:00 committed by GitHub
parent cd7b81c6d2
commit 29b8483fd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 51 additions and 70 deletions

View File

@ -9,8 +9,6 @@ plugins {
description = "gRPC: ALTS" description = "gRPC: ALTS"
evaluationDependsOn(project(':grpc-core').path)
dependencies { dependencies {
api project(':grpc-core') api project(':grpc-core')
implementation project(':grpc-auth'), implementation project(':grpc-auth'),
@ -28,7 +26,7 @@ dependencies {
shadow project(path: ':grpc-netty-shaded', configuration: 'shadow') shadow project(path: ':grpc-netty-shaded', configuration: 'shadow')
testImplementation project(':grpc-testing'), testImplementation project(':grpc-testing'),
project(':grpc-core').sourceSets.test.output, testFixtures(project(':grpc-core')),
project(':grpc-testing-proto'), project(':grpc-testing-proto'),
libraries.guava, libraries.guava,
libraries.junit, libraries.junit,

View File

@ -1,5 +1,6 @@
plugins { plugins {
id "java-library" id "java-library"
id "java-test-fixtures"
id "maven-publish" id "maven-publish"
id "me.champeau.jmh" id "me.champeau.jmh"
@ -8,15 +9,16 @@ plugins {
description = 'gRPC: API' description = 'gRPC: API'
evaluationDependsOn(project(':grpc-context').path)
dependencies { dependencies {
api project(':grpc-context'), api project(':grpc-context'),
libraries.jsr305, libraries.jsr305,
libraries.errorprone.annotations libraries.errorprone.annotations
implementation libraries.guava implementation libraries.guava
testImplementation project(':grpc-context').sourceSets.test.output, testFixturesImplementation libraries.guava,
libraries.junit,
libraries.mockito.core
testImplementation testFixtures(project(':grpc-context')),
project(':grpc-testing'), project(':grpc-testing'),
project(':grpc-grpclb') project(':grpc-grpclb')
testImplementation (libraries.guava.testlib) { testImplementation (libraries.guava.testlib) {
@ -32,3 +34,6 @@ tasks.named("javadoc").configure {
// We want io.grpc.Internal, but not io.grpc.Internal* // We want io.grpc.Internal, but not io.grpc.Internal*
exclude 'io/grpc/Internal?*.java' exclude 'io/grpc/Internal?*.java'
} }
components.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) { skip() }
components.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) { skip() }

View File

@ -19,7 +19,7 @@ dependencies {
testImplementation project(':grpc-testing'), testImplementation project(':grpc-testing'),
project(':grpc-testing-proto'), project(':grpc-testing-proto'),
project(':grpc-core').sourceSets.test.output // for FakeClock testFixtures(project(':grpc-core'))
testImplementation (libraries.guava.testlib) { testImplementation (libraries.guava.testlib) {
exclude group: 'junit', module: 'junit' exclude group: 'junit', module: 'junit'
} }

View File

@ -7,22 +7,6 @@ description = 'gRPC BinderChannel'
android { android {
namespace 'io.grpc.binder' namespace 'io.grpc.binder'
sourceSets {
test {
java {
srcDirs += "${projectDir}/../core/src/test/java/"
setIncludes(["io/grpc/internal/FakeClock.java",
"io/grpc/binder/**"])
}
}
androidTest {
java {
srcDirs += "${projectDir}/../core/src/test/java/"
setIncludes(["io/grpc/internal/AbstractTransportTest.java",
"io/grpc/binder/**"])
}
}
}
compileSdkVersion 31 compileSdkVersion 31
compileOptions { compileOptions {
sourceCompatibility 1.8 sourceCompatibility 1.8
@ -72,6 +56,7 @@ dependencies {
} }
testImplementation libraries.truth testImplementation libraries.truth
testImplementation project(':grpc-testing') testImplementation project(':grpc-testing')
testImplementation testFixtures(project(':grpc-core'))
androidTestAnnotationProcessor libraries.auto.value androidTestAnnotationProcessor libraries.auto.value
androidTestImplementation project(':grpc-testing') androidTestImplementation project(':grpc-testing')
@ -88,6 +73,7 @@ dependencies {
androidTestImplementation (libraries.guava.testlib) { androidTestImplementation (libraries.guava.testlib) {
exclude group: 'junit', module: 'junit' exclude group: 'junit', module: 'junit'
} }
androidTestImplementation testFixtures(project(':grpc-core'))
} }
import net.ltgt.gradle.errorprone.CheckSeverity import net.ltgt.gradle.errorprone.CheckSeverity

View File

@ -7,17 +7,15 @@ plugins {
description = 'gRPC: Census' description = 'gRPC: Census'
evaluationDependsOn(project(':grpc-api').path)
dependencies { dependencies {
api project(':grpc-api') api project(':grpc-api')
implementation libraries.guava, implementation libraries.guava,
libraries.opencensus.api, libraries.opencensus.api,
libraries.opencensus.contrib.grpc.metrics libraries.opencensus.contrib.grpc.metrics
testImplementation project(':grpc-api').sourceSets.test.output, testImplementation testFixtures(project(':grpc-api')),
project(':grpc-context').sourceSets.test.output, testFixtures(project(':grpc-context')),
project(':grpc-core').sourceSets.test.output, testFixtures(project(':grpc-core')),
project(':grpc-testing'), project(':grpc-testing'),
libraries.opencensus.impl libraries.opencensus.impl

View File

@ -1,5 +1,6 @@
plugins { plugins {
id "java" id "java"
id "java-test-fixtures"
id "maven-publish" id "maven-publish"
id "me.champeau.gradle.japicmp" id "me.champeau.gradle.japicmp"
@ -13,6 +14,10 @@ sourceCompatibility = 1.7
targetCompatibility = 1.7 targetCompatibility = 1.7
dependencies { dependencies {
testFixturesApi libraries.truth
// Explicitly choose the guava version to stay Java 7-compatible.
testFixturesImplementation 'com.google.guava:guava:30.1.1-android'
testFixturesImplementation libraries.jsr305
testImplementation libraries.jsr305 testImplementation libraries.jsr305
// Explicitly choose the guava version to stay Java 7-compatible. The rest of gRPC can move // Explicitly choose the guava version to stay Java 7-compatible. The rest of gRPC can move
// forward to Java 8-requiring versions. This is also only used for testing, so is unlikely to // forward to Java 8-requiring versions. This is also only used for testing, so is unlikely to
@ -23,3 +28,6 @@ dependencies {
signature "org.codehaus.mojo.signature:java17:1.0@signature" signature "org.codehaus.mojo.signature:java17:1.0@signature"
signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature" signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature"
} }
components.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) { skip() }
components.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) { skip() }

View File

@ -6,6 +6,7 @@ buildscript {
plugins { plugins {
id "java-library" id "java-library"
id "java-test-fixtures"
id "maven-publish" id "maven-publish"
id "me.champeau.gradle.japicmp" id "me.champeau.gradle.japicmp"
@ -19,9 +20,6 @@ import com.google.common.primitives.Bytes;
description = 'gRPC: Core' description = 'gRPC: Core'
evaluationDependsOn(project(':grpc-context').path)
evaluationDependsOn(project(':grpc-api').path)
dependencies { dependencies {
api project(':grpc-api') api project(':grpc-api')
implementation libraries.gson, implementation libraries.gson,
@ -30,8 +28,13 @@ dependencies {
libraries.errorprone.annotations, libraries.errorprone.annotations,
libraries.guava, libraries.guava,
libraries.perfmark.api libraries.perfmark.api
testImplementation project(':grpc-context').sourceSets.test.output, testFixturesApi libraries.junit
project(':grpc-api').sourceSets.test.output, testFixturesImplementation libraries.guava,
libraries.mockito.core,
libraries.truth,
project(':grpc-testing')
testImplementation testFixtures(project(':grpc-context')),
testFixtures(project(':grpc-api')),
project(':grpc-testing'), project(':grpc-testing'),
project(':grpc-grpclb') project(':grpc-grpclb')
testImplementation (libraries.guava.testlib) { testImplementation (libraries.guava.testlib) {
@ -61,6 +64,9 @@ animalsniffer {
] ]
} }
components.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) { skip() }
components.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) { skip() }
import net.ltgt.gradle.errorprone.CheckSeverity import net.ltgt.gradle.errorprone.CheckSeverity
def replaceBytes(byte[] haystack, byte[] needle, byte[] replacement) { def replaceBytes(byte[] haystack, byte[] needle, byte[] replacement) {

View File

@ -62,7 +62,7 @@ dependencies {
('io.opencensus:opencensus-api:0.31.1'), ('io.opencensus:opencensus-api:0.31.1'),
('com.google.guava:guava:31.1-jre') ('com.google.guava:guava:31.1-jre')
testImplementation project(':grpc-context').sourceSets.test.output, testImplementation testFixtures(project(':grpc-context')),
project(':grpc-testing'), project(':grpc-testing'),
project(':grpc-testing-proto') project(':grpc-testing-proto')
testImplementation (libraries.guava.testlib) { testImplementation (libraries.guava.testlib) {

View File

@ -13,7 +13,7 @@ dependencies {
project(':grpc-core'), project(':grpc-core'),
project(path: ':grpc-xds', configuration: 'shadow'), project(path: ':grpc-xds', configuration: 'shadow'),
libraries.guava.jre // JRE required by transitive protobuf-java-util libraries.guava.jre // JRE required by transitive protobuf-java-util
testImplementation project(':grpc-core').sourceSets.test.output testImplementation testFixtures(project(':grpc-core'))
signature libraries.signature.java signature libraries.signature.java
} }

View File

@ -9,8 +9,6 @@ plugins {
description = "gRPC: GRPCLB LoadBalancer plugin" description = "gRPC: GRPCLB LoadBalancer plugin"
evaluationDependsOn(project(':grpc-core').path)
dependencies { dependencies {
implementation project(':grpc-core'), implementation project(':grpc-core'),
project(':grpc-protobuf'), project(':grpc-protobuf'),
@ -21,7 +19,7 @@ dependencies {
runtimeOnly libraries.errorprone.annotations runtimeOnly libraries.errorprone.annotations
compileOnly libraries.javax.annotation compileOnly libraries.javax.annotation
testImplementation libraries.truth, testImplementation libraries.truth,
project(':grpc-core').sourceSets.test.output testFixtures(project(':grpc-core'))
signature libraries.signature.java signature libraries.signature.java
} }

View File

@ -13,10 +13,6 @@ configurations {
alpnagent alpnagent
} }
evaluationDependsOn(project(':grpc-core').path)
evaluationDependsOn(project(':grpc-context').path)
evaluationDependsOn(project(':grpc-api').path)
dependencies { dependencies {
implementation project(path: ':grpc-alts', configuration: 'shadow'), implementation project(path: ':grpc-alts', configuration: 'shadow'),
project(':grpc-auth'), project(':grpc-auth'),
@ -49,9 +45,9 @@ dependencies {
libraries.netty.tcnative.classes, libraries.netty.tcnative.classes,
project(':grpc-grpclb'), project(':grpc-grpclb'),
project(':grpc-rls') project(':grpc-rls')
testImplementation project(':grpc-context').sourceSets.test.output, testImplementation testFixtures(project(':grpc-context')),
project(':grpc-api').sourceSets.test.output, testFixtures(project(':grpc-api')),
project(':grpc-core').sourceSets.test.output, testFixtures(project(':grpc-core')),
libraries.mockito.core, libraries.mockito.core,
libraries.okhttp libraries.okhttp
alpnagent libraries.jetty.alpn.agent alpnagent libraries.jetty.alpn.agent

View File

@ -13,8 +13,6 @@ configurations {
alpnagent alpnagent
} }
evaluationDependsOn(project(':grpc-context').path)
dependencies { dependencies {
implementation project(':grpc-core'), implementation project(':grpc-core'),
project(':grpc-netty'), project(':grpc-netty'),
@ -28,9 +26,9 @@ dependencies {
runtimeOnly libraries.netty.tcnative, runtimeOnly libraries.netty.tcnative,
libraries.netty.tcnative.classes libraries.netty.tcnative.classes
testImplementation project(':grpc-context').sourceSets.test.output, testImplementation testFixtures(project(':grpc-context')),
project(':grpc-api').sourceSets.test.output, testFixtures(project(':grpc-api')),
project(':grpc-core').sourceSets.test.output, testFixtures(project(':grpc-core')),
libraries.mockito.core, libraries.mockito.core,
libraries.junit, libraries.junit,
libraries.truth libraries.truth

View File

@ -13,8 +13,6 @@ configurations {
alpnagent alpnagent
} }
evaluationDependsOn(project(':grpc-core').path)
dependencies { dependencies {
api project(':grpc-core'), api project(':grpc-core'),
libraries.netty.codec.http2 libraries.netty.codec.http2
@ -25,8 +23,8 @@ dependencies {
libraries.netty.unix.common libraries.netty.unix.common
// Tests depend on base class defined by core module. // Tests depend on base class defined by core module.
testImplementation project(':grpc-core').sourceSets.test.output, testImplementation testFixtures(project(':grpc-core')),
project(':grpc-api').sourceSets.test.output, testFixtures(project(':grpc-api')),
project(':grpc-testing'), project(':grpc-testing'),
project(':grpc-testing-proto'), project(':grpc-testing-proto'),
libraries.conscrypt, libraries.conscrypt,

View File

@ -8,8 +8,6 @@ plugins {
description = "gRPC: OkHttp" description = "gRPC: OkHttp"
evaluationDependsOn(project(':grpc-core').path)
dependencies { dependencies {
api project(':grpc-core') api project(':grpc-core')
implementation libraries.okio, implementation libraries.okio,
@ -18,8 +16,8 @@ dependencies {
// Make okhttp dependencies compile only // Make okhttp dependencies compile only
compileOnly libraries.okhttp compileOnly libraries.okhttp
// Tests depend on base class defined by core module. // Tests depend on base class defined by core module.
testImplementation project(':grpc-core').sourceSets.test.output, testImplementation testFixtures(project(':grpc-core')),
project(':grpc-api').sourceSets.test.output, testFixtures(project(':grpc-api')),
project(':grpc-testing'), project(':grpc-testing'),
project(':grpc-testing-proto'), project(':grpc-testing-proto'),
libraries.netty.codec.http2, libraries.netty.codec.http2,

View File

@ -8,8 +8,6 @@ plugins {
description = "gRPC: RouteLookupService Loadbalancing plugin" description = "gRPC: RouteLookupService Loadbalancing plugin"
evaluationDependsOn(project(':grpc-core').path)
dependencies { dependencies {
implementation project(':grpc-core'), implementation project(':grpc-core'),
project(':grpc-protobuf'), project(':grpc-protobuf'),
@ -22,7 +20,7 @@ dependencies {
project(':grpc-grpclb'), project(':grpc-grpclb'),
project(':grpc-testing'), project(':grpc-testing'),
project(':grpc-testing-proto'), project(':grpc-testing-proto'),
project(':grpc-core').sourceSets.test.output // for FakeClock testFixtures(project(':grpc-core'))
signature libraries.signature.java signature libraries.signature.java
} }

View File

@ -16,8 +16,6 @@ tasks.named("compileJava").configure {
] ]
} }
evaluationDependsOn(project(':grpc-core').path)
dependencies { dependencies {
api project(':grpc-protobuf'), api project(':grpc-protobuf'),
project(':grpc-stub'), project(':grpc-stub'),
@ -30,7 +28,7 @@ dependencies {
compileOnly libraries.javax.annotation compileOnly libraries.javax.annotation
testImplementation project(':grpc-testing'), testImplementation project(':grpc-testing'),
libraries.netty.transport.epoll, // for DomainSocketAddress libraries.netty.transport.epoll, // for DomainSocketAddress
project(':grpc-core').sourceSets.test.output // for FakeClock testFixtures(project(':grpc-core'))
testCompileOnly libraries.javax.annotation testCompileOnly libraries.javax.annotation
signature libraries.signature.java signature libraries.signature.java
} }

View File

@ -8,8 +8,6 @@ plugins {
description = "gRPC: Testing" description = "gRPC: Testing"
evaluationDependsOn(project(':grpc-core').path)
dependencies { dependencies {
api project(':grpc-core'), api project(':grpc-core'),
project(':grpc-stub'), project(':grpc-stub'),
@ -24,7 +22,7 @@ dependencies {
} }
testImplementation project(':grpc-testing-proto'), testImplementation project(':grpc-testing-proto'),
project(':grpc-core').sourceSets.test.output testFixtures(project(':grpc-core'))
signature libraries.signature.java signature libraries.signature.java
signature libraries.signature.android signature libraries.signature.android

View File

@ -11,8 +11,6 @@ plugins {
description = "gRPC: XDS plugin" description = "gRPC: XDS plugin"
evaluationDependsOn(project(':grpc-core').path)
sourceSets { sourceSets {
thirdparty { thirdparty {
java { java {
@ -57,7 +55,7 @@ dependencies {
def nettyDependency = implementation project(':grpc-netty') def nettyDependency = implementation project(':grpc-netty')
testImplementation project(':grpc-rls') testImplementation project(':grpc-rls')
testImplementation project(':grpc-core').sourceSets.test.output testImplementation testFixtures(project(':grpc-core'))
annotationProcessor libraries.auto.value annotationProcessor libraries.auto.value
// At runtime use the epoll included in grpc-netty-shaded // At runtime use the epoll included in grpc-netty-shaded