Repository navigation
chore(build): Compile with a JDK 21 toolchain and upgrade Mockito and Error Prone #6242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+514
โ540
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
01efed6
build: Switch to JDK 21 and upgrade Mockito, Robolectric and Error Prone
markushi 8ff189d
build: Compile tests for JDK 21 and fix buildSrc JVM target
markushi 3dc76c0
build: Compile with a JDK 21 toolchain from a build-logic convention โฆ
markushi 26b8a60
docs(kafka): Explain the explicit double cast at the latency call site
markushi 9788085
build: Compile the samples and their tests with the toolchain JDK
markushi f6de52d
Format code
getsentry-bot 6e81176
build: Drop the now-unused JvmTarget imports from the samples
markushi 1c7fbf3
build: Clarify the jvm-targets plugin comments and rename its helper
markushi 5c8907d
Merge branch 'build/jdk-21' of github.com:getsentry/sentry-java into โฆ
markushi 7bd342c
build: Require JDK 21 to run Gradle again
markushi 37b01cf
build: Keep the Spring Boot 2 sample apps on their published bytecodeโฆ
markushi d663f01
ci: Drop the stale Java version from the build job name
markushi 445f5e4
build: Keep Robolectric at 4.15 and leave its test environment untouched
markushi 2de047f
build: Move the Java 8 release pin into the jvm-targets convention plโฆ
markushi 561324b
build: Drop the Error Prone and NullAway code fixes, they move to theโฆ
markushi 2c629ba
Merge remote-tracking branch 'origin/main' into build/jdk-21
markushi ddae2a9
ci: Drop the stale Java version from the build job name
markushi aaa1ef0
fix(core): Suppress the new Error Prone and javac 21 findings in the โฆ
markushi fef4772
fix(core): Resolve the remaining Error Prone and javac 21 findings inโฆ
markushi 61c4352
build: Move the JDK and bytecode level decisions into the io.sentry.cโฆ
markushi c667f66
Address PR comments
markushi 4d4654d
test(android): Make the flush timeout verifies match the real log call
markushi 982954a
chore(core): Reword the JDK 21 suppression comments
markushi 38288e8
build: Keep only the javac unit test targets inside afterEvaluate
markushi e387384
Merge remote-tracking branch 'origin/main' into build/jdk-21
markushi a2345fc
build: Drop afterEvaluate, pin the Kotlin API level and rename the coโฆ
markushi 975708e
Fix JDK 21 findings in sentry-android-core (#6261)
markushi 1ee7acc
Fix JDK 21 findings in the Spring modules (#6260)
markushi 0f3f8bc
Fix JDK 21 findings in the JVM integrations (#6259)
markushi 2b6f9fa
Merge branch 'main' into build/jdk-21
markushi 17e2b85
fix multiplatform target compilations
markushi 374ff7d
Merge remote-tracking branch 'origin/main' into build/jdk-21
markushi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
build-logic/src/main/kotlin/io/sentry/gradle/JdkTargetConvention.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package io.sentry.gradle | ||
|
|
||
| import com.android.build.gradle.BaseExtension | ||
| import org.gradle.api.JavaVersion | ||
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.artifacts.VersionCatalogsExtension | ||
| import org.gradle.api.plugins.JavaBasePlugin | ||
| import org.gradle.api.plugins.JavaPluginExtension | ||
| import org.gradle.api.tasks.compile.JavaCompile | ||
| import org.gradle.jvm.toolchain.JavaLanguageVersion | ||
| import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
| import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension | ||
| import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension | ||
| import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget | ||
| import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile | ||
|
|
||
| /** The JDK every module compiles and tests with, whatever JDK runs Gradle. */ | ||
| private val BUILD_JDK = JavaLanguageVersion.of(21) | ||
|
|
||
| /** The level the SDK publishes, so that Java 8 consumers can still use it. */ | ||
| private val PUBLISHED_JAVA_VERSION = JavaVersion.VERSION_1_8 | ||
|
|
||
| /** | ||
| * Holds every toolchain, bytecode level decision and compilation option of a module. It does the | ||
| * following | ||
| * - sample apps target the build JDK (21) | ||
| * - unit test code will target the build JDK (21) (required for Mockito 5) | ||
| * - published JVM modules main code pins the Java 1.8 release, for Java and for Kotlin | ||
| * - published Android modules main code targets Java 1.8 | ||
| * - minSdk is set for Android libraries | ||
| */ | ||
| class JdkTargetConvention : Plugin<Project> { | ||
| override fun apply(project: Project) { | ||
| project.plugins.withType(JavaBasePlugin::class.java) { | ||
| project.extensions.getByType(JavaPluginExtension::class.java).toolchain { | ||
| languageVersion.set(BUILD_JDK) | ||
| } | ||
| } | ||
|
|
||
| project.plugins.withId("com.vanniktech.maven.publish") { | ||
|
markushi marked this conversation as resolved.
|
||
| // Only works for non-android modules | ||
| // See https://issuetracker.google.com/issues/278800528 | ||
| project.plugins.withId("java-library") { | ||
| project.tasks.named("compileJava", JavaCompile::class.java) { | ||
| options.release.set(PUBLISHED_JAVA_VERSION.majorVersion.toInt()) | ||
| } | ||
| } | ||
| // -Xjdk-release is the Kotlin counterpart of release: without it Kotlin resolves against the | ||
| // build JDK and happily compiles e.g. Files.readString() into Java 8 bytecode. The version | ||
| // follows jvmTarget, which the modules that publish a higher level set themselves. | ||
| project.plugins.withId("org.jetbrains.kotlin.jvm") { | ||
| project.tasks.named("compileKotlin", KotlinJvmCompile::class.java) { | ||
| compilerOptions.freeCompilerArgs.add( | ||
|
markushi marked this conversation as resolved.
|
||
| compilerOptions.jvmTarget.map { "-Xjdk-release=${it.target}" } | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| project.plugins.withId("com.android.library") { | ||
| val android = project.extensions.getByType(BaseExtension::class.java) | ||
|
markushi marked this conversation as resolved.
|
||
| android.compileOptions { | ||
| sourceCompatibility = PUBLISHED_JAVA_VERSION | ||
| targetCompatibility = PUBLISHED_JAVA_VERSION | ||
| } | ||
| android.defaultConfig { aarMetadata { minCompileSdk = project.minSdk() } } | ||
| } | ||
|
|
||
| listOf("com.android.library", "com.android.application").forEach { pluginId -> | ||
| project.plugins.withId(pluginId) { project.targetBuildJdkForUnitTests() } | ||
| } | ||
| } | ||
|
|
||
| private fun Project.minSdk(): Int = | ||
|
markushi marked this conversation as resolved.
|
||
| extensions | ||
| .getByType(VersionCatalogsExtension::class.java) | ||
| .named("libs") | ||
| .findVersion("minSdk") | ||
| .orElseThrow { IllegalStateException("libs.versions.minSdk is missing") } | ||
| .requiredVersion | ||
| .toInt() | ||
|
|
||
| /** | ||
| * Mockito 5 and mockito-kotlin 6 are built for Java 11, so test code - which is never published - | ||
| * cannot share the Java 8 target of the main code. AGP has no per variant compileOptions, so this | ||
| * goes through the Kotlin compilations: their compile task providers are configured after AGP | ||
| * wrote its own compileOptions, which an apply time configureEach would lose against. | ||
| */ | ||
| private fun Project.targetBuildJdkForUnitTests() { | ||
| plugins.withId("org.jetbrains.kotlin.android") { | ||
| extensions.getByType(KotlinAndroidProjectExtension::class.java).target.targetBuildJdk() | ||
| } | ||
| plugins.withId("org.jetbrains.kotlin.multiplatform") { | ||
| extensions | ||
| .getByType(KotlinMultiplatformExtension::class.java) | ||
| .targets | ||
| .withType(KotlinAndroidTarget::class.java) | ||
| .configureEach { targetBuildJdk() } | ||
| } | ||
| } | ||
|
|
||
| private fun KotlinAndroidTarget.targetBuildJdk() { | ||
| compilations.configureEach { | ||
| if (name.endsWith("UnitTest")) { | ||
| compileTaskProvider.configure { | ||
| compilerOptions.jvmTarget.set(JvmTarget.fromTarget(BUILD_JDK.toString())) | ||
| } | ||
| compileJavaTaskProvider?.configure { | ||
| sourceCompatibility = BUILD_JDK.toString() | ||
| targetCompatibility = BUILD_JDK.toString() | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,3 @@ | ||
| import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
|
||
| plugins { | ||
| `kotlin-dsl` | ||
| } | ||
|
|
||
| tasks.withType<KotlinCompile>().configureEach { | ||
|
markushi marked this conversation as resolved.
|
||
| compilerOptions.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.