任务 ':compileJava' 执行失败。> 无效的源发布:1.7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30450923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Execution failed for task ':compileJava'. > invalid source release: 1.7
提问by BdEngineer
I am using :
我在用 :
- gradle-2.3
- javac -version = 1.7
- jre = 1.7
- regedit shows it is pointing to 1.7.
- gradle-2.3
- javac -version = 1.7
- jre = 1.7
- regedit 显示它指向 1.7。
But I am still getting below error
但我仍然低于错误
Execution failed for task ':compileJava'. > invalid source release: 1.7
任务 ':compileJava' 执行失败。> 无效的源发布:1.7
Please let me know how to fix it.
请让我知道如何修复它。
回答by Julian Pieles
Try the following in your build gradle:
在您的构建 gradle 中尝试以下操作:
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
If this does not work please provide the contents of your build.gradle.
如果这不起作用,请提供 build.gradle 的内容。
回答by Kris
You say you are running with Java 7, but are you really sure?
您说您使用的是 Java 7,但您真的确定吗?
Because as far as I know that error occurs precisely when you are using a source / target level that is not supported by the JVM you are running gradle with. So if I were to take a guess I'd say that gradle seems to think your JDK doesn't support Java 7 (so its JDK 6 or lower)
因为据我所知,当您使用运行 gradle 的 JVM 不支持的源/目标级别时,错误就会发生。因此,如果我要猜测,我会说 gradle 似乎认为您的 JDK 不支持 Java 7(因此它的 JDK 6 或更低版本)
Maybe double check that
也许仔细检查一下
a) Gradle itself is running with JDK 7. If you run gradle from within Eclipse using the STS gradle tooling, it will use the workspace default JRE to run gradle. Check that it is at least a JDK 7. (Go to "Windows >> Preferences >> Java >> Installed JRE". The JRE with a 'check mark' is the one Gradle will run with).
a) Gradle 本身运行 JDK 7。如果您使用 STS gradle 工具从 Eclipse 中运行 gradle,它将使用工作区默认 JRE 来运行 gradle。检查它是否至少是 JDK 7。(转到“Windows >> Preferences >> Java >> Installed JRE”。带有“复选标记”的 JRE 是 Gradle 将使用的一个)。
b) Gradle may accidentally pick up another JDK to compile stuff with if it finds an environment variable 'JAVA_HOME'. So double check that it isn't pointing to a JDK 6 or lower.
b) 如果 Gradle 找到环境变量“JAVA_HOME”,它可能会意外地选择另一个 JDK 来编译内容。因此,请仔细检查它是否指向 JDK 6 或更低版本。
回答by Jens
You can set the JDK Version used by gradle for the build by adding a "gradle.properties" file to your project. Add the following property:
您可以通过向项目添加“gradle.properties”文件来设置 gradle 用于构建的 JDK 版本。添加以下属性:
org.gradle.java.home = <Path to the JDK you want to use for your project>
I agree with the previous answer that you also should check if the JDK and the sourceCompatibility match.
我同意之前的答案,您还应该检查 JDK 和 sourceCompatibility 是否匹配。
回答by Pam Stums
In my case Gradle ran on JRE instead of JDK(wrong set of JAVA_HOME). Pointing my JAVA_HOME to the root of the JDK fixed the build. (Of course, assuming your PATH has %JAVA_HOME%\bin)
在我的情况下,Gradle 在 JRE 上运行而不是JDK(错误的 JAVA_HOME 集)。将我的 JAVA_HOME 指向 JDK 的根目录修复了构建。(当然,假设你的 PATH 有 %JAVA_HOME%\bin)
Reason:
原因:
The JDK has the javac for compiling java while the JRE does not.
JDK 有用于编译 java 的 javac,而 JRE 没有。
回答by sparksen
Just had the "bug" with 1.8 java
刚刚有 1.8 java 的“错误”
Solved: Findbugs showed me an ü in a method title ( not allowed in graddle)
已解决:Findbugs 在方法标题中向我显示了 ü(在 graddle 中不允许)
回答by Shan Lastmile
to check if the $JAVA_HOME is really to point the default java
# echo $JAVA_HOME
/usr/lib/jvm/java-1.7.0-openjdk
# java -version
openjdk version "1.8.0_151"
if misaligned like above, to modify $JAVA_HOME in the /etc/profile (or alternatively the .profile/.bashprofile/ in your user's home directory)
let point to JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
BTW: solved at Centos7 to fix Invalid release 1.8
检查 $JAVA_HOME 是否真的指向默认 java
# echo $JAVA_HOME
/usr/lib/jvm/java-1.7.0-openjdk
# java -version
openjdk version "1.8.0_151" 如果像上面一样未对齐,修改 /etc/profile 中的 $JAVA_HOME (或者你的用户主目录中的 .profile/.bashprofile/)让我们指向 JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk 顺便说一句:在 Centos7 解决以修复无效的版本 1.8