最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

kotlin - Different java versions in gradle subprojects - Stack Overflow

programmeradmin6浏览0评论

I'm facing an issue with gradle when trying to build the project using different java versions. The main project is configured to be used java 21 in its gradle file:

java {
    sourceCompatibility = JavaVersion.VERSION_21
}

Now, I've created a module called "models". This module needs to be compiled to java 11. This module is included as a dependency in the main project but also exported as a jar library that needs to be compiled with java 11.

The new "models" module declares java 11 like this:

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

kotlin {
    compilerOptions {
        jvmTarget = JvmTarget.JVM_11
    }
}

With the different java configurations, I get the following error:

Could not resolve all dependencies for configuration ':runtimeClasspath'. Could not resolve project :models. Required by: root project : No matching variant of project :models was found. The consumer was configured to find a library for use during runtime, compatible with Java 21, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute '.jetbrains.kotlin.platform.type' with value 'jvm' but:

  • No variants exist

I was not expecting incompatibility issues by using a lower version of java in one of my modules but gradle is strict about java versions and requiring the same java version in the root project and the subproject. I'd like to find a way to either disable this restriction or specifying somehow that both versions should be perfectly compatible.

发布评论

评论列表(0)

  1. 暂无评论