How to specify source and target compatibility in Java module?(如何在 Java 模块中指定源和目标兼容性?)
问题描述
我有一个 Gradle 项目,其中包含一个 Android 模块(com.android.library
插件应用在 build.gradle
文件中)和一个 Java 模块(java
插件应用在 build.gradle
文件中).在 Java 模块的 build.gradle
文件中,我之前指定了源和目标的兼容性,如下所示:
I have a Gradle project consisting of an Android module (the com.android.library
plugin is applied in the build.gradle
file) and a Java module (the java
plugin is applied in the build.gradle
file). Within the build.gradle
file of the Java module I was previously specifying the source and target compatibility as follows:
apply plugin: 'java'
compileJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
我刚刚将项目的Android Plugin for Gradle"和Gradle Wrapper"版本更新为最新版本(分别为 2.2.3 和 3.2.1),现在我在 Java 模块中看到如下警告:
I've just updated the project's "Android Plugin for Gradle" and "Gradle Wrapper" versions to the latest releases (2.2.3 and 3.2.1 respectively) and I'm now seeing warnings in the Java module as follows:
Access to 'sourceCompatibility' exceeds its access rights
Access to 'targetCompatibility' exceeds its access rights
如果我将 sourceCompatibility
和 targetCompatibility
声明移动到模块的 build.gradle
文件的根级别,如下所示...
If I move the sourceCompatibility
and targetCompatibility
declarations to the root-level of the module's build.gradle
file as follows...
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
...然后我收到警告消息,告诉我分配未使用.
... then I get warning messages telling me that the assignments are not used.
在最新的 Gradle 版本中指定 Java 模块的源和目标兼容级别的正确方式是什么?
What is the correct manner of specifying the source and target compatibility level of a Java module in the latest Gradle release?
推荐答案
我认为最后一个(根中的声明)是正确的,它必须正常工作,尽管它会在 IDE 中引起警告.无处可说,声明它的首选方式是什么,official docs,它被用作:
I think that the last one(declaration in the root) is the correct one and it has to work properly, though it causes warnings in IDE. It's nowhere said, what is the prefered way to declare it and there is only one example in the official docs, where it's used as:
sourceCompatibility = 1.6
在 build.gradle
的根目录中.
这篇关于如何在 Java 模块中指定源和目标兼容性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Java 模块中指定源和目标兼容性?
基础教程推荐
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01