我维护一个内部库,并将构建和发布JDK的JDK从11升级到17,同时还从6.8.1级升级到7.4.2级。
在某些现有项目中尝试使用库的新版本时,我会得到以下错误:
Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 11这是非常不言自明的,但我不明白,因为在我的库中,我在我的gradle.build文件中定义了它:
sourceCompatibility = 11
targetCompatibility = 11 因此,我希望我构建的jar与JDK 11兼容。但很明显这不是。
我错过了什么?
发布于 2022-07-20 15:38:09
看起来,在最新的Gradle版本中,我们需要使用toolchain (而不是sourceCompatibility / targetCompatibility )来定义我们生成的jar的兼容性。
当我使用:
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}https://stackoverflow.com/questions/73054491
复制相似问题