diff --git a/api/build.gradle b/api/build.gradle index 6906a2ae0d9..bc2301cee35 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -16,9 +16,13 @@ sourceSets { } } -compileContextJava { - sourceCompatibility = 1.7 - targetCompatibility = 1.7 +tasks.named("compileContextJava").configure { + if (JavaVersion.current().isJava9Compatible()) { + options.release = 7 + } else { + sourceCompatibility = 1.7 + targetCompatibility = 1.7 + } } diff --git a/build.gradle b/build.gradle index 31801ef291b..13d8d819ee4 100644 --- a/build.gradle +++ b/build.gradle @@ -181,9 +181,6 @@ subprojects { } plugins.withId("java") { - sourceCompatibility = 1.8 - targetCompatibility = 1.8 - dependencies { testImplementation libraries.junit, libraries.mockito.core, @@ -239,6 +236,14 @@ subprojects { } } + tasks.withType(JavaCompile).configureEach { + if (JavaVersion.current().isJava9Compatible()) { + options.release = 8 + } else { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 + } + } tasks.named("compileJava").configure { // This project targets Java 7 (no time.Duration class) options.errorprone.check("PreferJavaTimeOverload", CheckSeverity.OFF) @@ -279,10 +284,6 @@ subprojects { plugins.withId("me.champeau.jmh") { // invoke jmh on a single benchmark class like so: // ./gradlew -PjmhIncludeSingleClass=StatsTraceContextBenchmark clean :grpc-core:jmh - tasks.named("compileJmhJava").configure { - sourceCompatibility = 1.8 - targetCompatibility = 1.8 - } tasks.named("jmh").configure { warmupIterations = 10 iterations = 10 diff --git a/gae-interop-testing/gae-jdk8/build.gradle b/gae-interop-testing/gae-jdk8/build.gradle index 78cadc60582..f3ff765ddfb 100644 --- a/gae-interop-testing/gae-jdk8/build.gradle +++ b/gae-interop-testing/gae-jdk8/build.gradle @@ -90,9 +90,6 @@ appengine { group = 'io.grpc' // Generated output GroupId version = '1.0-SNAPSHOT' // Version in generated output -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - /** Returns the service name. */ String getGaeProject() { def stream = new ByteArrayOutputStream() diff --git a/servlet/build.gradle b/servlet/build.gradle index f5ef32ae11e..50f06f60ae7 100644 --- a/servlet/build.gradle +++ b/servlet/build.gradle @@ -5,10 +5,6 @@ plugins { description = "gRPC: Servlet" -// javax.servlet-api 4.0 requires a minimum of Java 8, so we might as well use that source level -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - def jettyVersion = '10.0.7' configurations { diff --git a/servlet/jakarta/build.gradle b/servlet/jakarta/build.gradle index 59f5ac78d80..7b784bce9ac 100644 --- a/servlet/jakarta/build.gradle +++ b/servlet/jakarta/build.gradle @@ -4,8 +4,6 @@ plugins { } description = "gRPC: Jakarta Servlet" -sourceCompatibility = 1.8 -targetCompatibility = 1.8 // Set up classpaths and source directories for different servlet tests configurations {