Reputation: 11
I used Kotlin Gradle plugin in my project and I set JVM target to 1.8. However, I found the published module -- the gradle variants don't respect that.
apply plugin: "kotlin"
compileKotlin {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
}
Here I want to set the target Java version as 1.8. And I checked the bytecodes of the build classes and it is Java 1.8.
gradle outgoingVariants
Attributes
- org.gradle.category = library
- org.gradle.dependency.bundling = external
- org.gradle.jvm.version = 11
...
When I used the gradle task outgoingVariants
it appears that the JVM version is the same as the one in my local (I uses Java 11).
So when this library was published into central repository, I can only use Java 11 in my main project to add this dependency, although the bytecode is actually 1.8.
Is there a way that I can keep the gradle variants respecting the Kotlin JVM target settings?
Upvotes: 1
Views: 967
Reputation: 11
You can manually set the attribute value as a workaround solution. Use something like this:
configurations["runtimeElements"].attributes {
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8)
}
Upvotes: 1