Specify Java language level in module plugin#3732
Conversation
Codecov Report
@@ Coverage Diff @@
## main #3732 +/- ##
=========================================
Coverage 78.04% 78.04%
Complexity 2883 2883
=========================================
Files 473 473
Lines 9300 9300
Branches 1767 1767
=========================================
Hits 7258 7258
Misses 1078 1078
Partials 964 964 Continue to review full report at Codecov.
|
| java { | ||
| withSourcesJar() | ||
| withJavadocJar() | ||
| sourceCompatibility = JavaVersion.VERSION_1_8 |
There was a problem hiding this comment.
Shouldn't need sourceCompatibility set here, since there's no Java source in the project.
There was a problem hiding this comment.
I believe you're right, although I wasn't able to find any reference that sourceCompatibility is using only for compilation of Java file and I can't exclude other side effects. I won't mind keeping both.
| withSourcesJar() | ||
| withJavadocJar() | ||
| sourceCompatibility = JavaVersion.VERSION_1_8 | ||
| targetCompatibility = JavaVersion.VERSION_1_8 |
There was a problem hiding this comment.
Dropping targetCompatibility in #3575 breaking things here is unfortunate, and obviously not expected :(. Kotlin apparently ignores the jvmTarget option on the compilation tasks, or at least that value doesn't filter down to the generated JARs.
JetBrains says the proper way to set the value is with this:
configurations["runtimeElements"].attributes {
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8)
}But I agree setting targetCompatibility here is easier to understand.
There was a problem hiding this comment.
Yeah the suggested approach feel really fragile. I've ⭐ the YouTrack issue. Ideally this could be addressed by the KGP in some form.
There was a problem hiding this comment.
This is probably the behavior configured in Gradle: https://github.com/gradle/gradle/blob/v7.0.0/subprojects/plugins/src/main/java/org/gradle/api/plugins/jvm/internal/DefaultJvmPluginServices.java#L211 - The target compatibility is used to configure the org.gradle.jvm.version attribute
picklebento
left a comment
There was a problem hiding this comment.
This is probably worth paying attention to in future Gradle upgrades.
|
This PR is likely not necessary when we bump to Kotlin 1.5
|
From #3727 (comment)
We need to specify the Java
sourceCompatibilityandtargetCompatibilityinside themoduleplugin.Sadly the -RC1 was build with JDK11 and and this makes it unusable for users on JRE 8
Fixes #3731