Gradle学习踩坑记录
gradle学习踩坑记录
最近想学习一下Java11,使用gradle搭建了一个项目,但是在执行打包命令./gradlew clean build
时报错如下:
1 | Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)' |
原因是因为我本地的JAVA_HOME配置的JDK版本是1.8,但是项目中指定的编译版本为Java11:
1 | sourceCompatibility = JavaVersion.VERSION_11 |
解决方式是在项目的根目录下新建gradle.properties文件,并写入以下配置,问题解决
1 | /Library/Java/JavaVirtualMachines/jdk-11.0.9.jdk/Contents/Home = |
gradle的官方文档解释如下:
Resolve the Gradle JVM version for the existing project
- IntelliJ IDEA checks the
gradle.properties
file for the appropriate Gradle JVM specified inorg.gradle.java.home
and uses it for the project. - Then it checks the
JAVA_HOME
environment variable. - Then it checks the closest appropriate JDK version for the existing Gradle version.