如何在Java模块中指定源和目标兼容性? [英] How to specify source and target compatibility in Java module?
问题描述
我有一个由Android模块组成的Gradle项目( com.android.library
插件应用于 build.gradle
file)和一个Java模块(在 build.gradle
文件中应用 java
插件)。在Java模块的 build.gradle
文件中,我之前指定了源和目标兼容性如下:
apply plugin:'java'
compileJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
code>
我刚刚更新了项目的Android Gradle for Gradle和Gradle Wrapper版本到最新版本(2.2.3和3.2.1),现在我看到Java模块中的警告如下:
访问'sourceCompatibility'超过其访问权限
访问'targetCompatibility'超出其访问权限
如果我将 sourceCompatibility
和 targetCompatibility
声明到模块的 build.gradle
pre $ apply plugin:'java'
sourceCompatibility = 1.7
targ etCompatibility = 1.7
...然后我收到警告消息,告诉我没有使用任务。 / p>
在最新的Gradle版本中指定Java模块的源和目标兼容级别的正确方式是什么?
我认为最后一个(根中的声明)是正确的,它必须正常工作,尽管它会在IDE中引发警告。无处可谈,声明它的最佳方式是什么,并且官方文档,它用作:
sourceCompatibility = 1.6
$在 build.gradle
的根目录下的c $ c>
。
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
}
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
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.
What is the correct manner of specifying the source and target compatibility level of a Java module in the latest Gradle release?
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
in the root of the build.gradle
.
这篇关于如何在Java模块中指定源和目标兼容性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!