diff --git a/api/build.gradle b/api/build.gradle index 384ab9be1c3..2d94ed0eb0b 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 + } } tasks.named("jar").configure { diff --git a/build.gradle b/build.gradle index deaa6d82ef6..a0d20cafebd 100644 --- a/build.gradle +++ b/build.gradle @@ -182,9 +182,6 @@ subprojects { } plugins.withId("java") { - sourceCompatibility = 1.8 - targetCompatibility = 1.8 - dependencies { testImplementation libraries.junit, libraries.mockito.core, @@ -240,6 +237,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) @@ -285,10 +290,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 3ed315b388f..71f3dfb38d4 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 8df1b93d83a..40f61c0a407 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 {