|
| 1 | +import org.gradle.api.tasks.testing.logging.TestExceptionFormat |
| 2 | +import org.gradle.api.tasks.testing.logging.TestLogEvent |
| 3 | + |
| 4 | +plugins { |
| 5 | + id("internal.common-convention") |
| 6 | + id("java-library") |
| 7 | +} |
| 8 | + |
| 9 | +// The project is built using a JDK 25 toolchain, but the main sources are compiled with --release 17. |
| 10 | +// |
| 11 | +// This means: |
| 12 | +// - Gradle can run on any JDK 17+, |
| 13 | +// - javac from JDK 25 is used, |
| 14 | +// - the produced bytecode and available Java API for main sources are restricted to Java 17. |
| 15 | +// |
| 16 | +// This setup lets us use a modern JDK for tooling (ErrorProne, NullAway) while keeping Java 17 binary compatibility for |
| 17 | +// library consumers. |
| 18 | +// |
| 19 | +// Tests are NOT compiled with --release XYZ, so they may use newer Java APIs. |
| 20 | + |
| 21 | +java { |
| 22 | + toolchain.languageVersion = JavaLanguageVersion.of(25) |
| 23 | +} |
| 24 | + |
| 25 | +tasks.withType<JavaCompile>().configureEach { |
| 26 | + options.compilerArgs.add("-parameters") |
| 27 | + options.encoding = "UTF-8" |
| 28 | +} |
| 29 | + |
| 30 | +tasks.named<JavaCompile>("compileJava") { |
| 31 | + options.release = 17 |
| 32 | +} |
| 33 | + |
| 34 | +tasks.withType<Test>().configureEach { |
| 35 | + useJUnitPlatform() |
| 36 | + |
| 37 | + testLogging { |
| 38 | + events(TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED) |
| 39 | + exceptionFormat = TestExceptionFormat.SHORT |
| 40 | + showStandardStreams = true |
| 41 | + } |
| 42 | + |
| 43 | + // For resolving warnings from mockito. |
| 44 | + jvmArgs("-XX:+EnableDynamicAgentLoading") |
| 45 | + |
| 46 | + systemProperty("user.language", "en") |
| 47 | + systemProperty("user.country", "US") |
| 48 | +} |
| 49 | + |
| 50 | +tasks.withType<Javadoc>().configureEach { |
| 51 | + javadocTool = javaToolchains.javadocToolFor { languageVersion.set(JavaLanguageVersion.of(17)) } |
| 52 | +} |
| 53 | + |
| 54 | +tasks.withType<Jar>().configureEach { |
| 55 | + manifest { |
| 56 | + attributes["Implementation-Title"] = project.name |
| 57 | + attributes["Implementation-Version"] = project.version |
| 58 | + attributes["Created-By"] = "Gradle ${gradle.gradleVersion}" |
| 59 | + } |
| 60 | + from("${rootProject.rootDir}/LICENSE") { |
| 61 | + into("META-INF/") |
| 62 | + rename { "LICENSE.txt" } |
| 63 | + } |
| 64 | +} |
0 commit comments