Which should I use with Kotlin 1.7 to replace `tar...
# gradle
j
Which should I use with Kotlin 1.7 to replace
targetCompatibility
and
sourceCompatibility
?
a
You should not use them for Kotlin. JVM bytecode generated by Kotlin is affected by
kotlinOptions.jvmTarget
j
Ah, nice, thank you!
v
Or you simply set a JVM Toolchain. Kotlin Gradle Plugin does adapt to it.
☝️ 1
j
We have only Kotlin code in that module, which would be the difference?
Basically we only need to use JVM 1.8, but we are not doing anything special
v
Doesn't matter whether you only have Kotlin code or not. You can set the
jvmTarget
directly, or you can simply set the JVM Toolchain. If you do the latter you would be save when adding Java code later, but other than that I don't think it makes a difference.
👍 2
r
Not quite the same thing. Toolchains define what JVM compiler is used, whereas JVM target sets the version of the bytecode generated. Newer compilers, both java and kotlin (set via toolchains), can still compile to older bytecode.
v
But no JVM compiler is used as he has no Java sources and the JVM target is derived from the toolchain setting. So where is the difference?
r
True. I'm just pointing out there is a difference and toolchain just sets the default for jvmTarget. It doesn't have to match. Personally I prefer to be explicit in setting both the toolchain and jvmTarget.
j
@Alexander.Likhachev We have seen issues after removing it. We need Java 11 to compile it but we are setting the
jvmTarget = "1.8"
. In this error we have tried with Java 17 but we have tried with more Java versions and the
jvmTarget = "1.8"
If we remove the Gradle plugins which need Java 11 and we compile with Java 8. It works.
Copy code
Could not determine the dependencies of task ':analysis:low-level-api-fir:compileJava'.
> Could not resolve all task dependencies for configuration ':analysis:low-level-api-fir:compileClasspath'.
   > Could not resolve io.arrow-kt:inject-compiler-plugin:0.1.0.
     Required by:
         project :analysis:low-level-api-fir
      > No matching variant of io.arrow-kt:inject-compiler-plugin:0.1.0 was found. The consumer was configured to find an API of a library compatible with Java 8, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
          - Variant 'apiElements' capability io.arrow-kt:inject-compiler-plugin:0.1.0 declares an API of a library, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
          - Variant 'runtimeElements' capability io.arrow-kt:inject-compiler-plugin:0.1.0 declares a runtime of a library, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
   > Could not resolve io.arrow-kt:inject-annotations:0.1.0.
     Required by:
         project :analysis:low-level-api-fir
      > No matching variant of io.arrow-kt:inject-annotations:0.1.0 was found. The consumer was configured to find an API of a library compatible with Java 8, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
          - Variant 'apiElements' capability io.arrow-kt:inject-annotations:0.1.0 declares an API of a library, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
          - Variant 'runtimeElements' capability io.arrow-kt:inject-annotations:0.1.0 declares a runtime of a library, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
a
@Javier Could you please try the workaround suggested here?