使用gradle构建项目

问题描述

到目前为止,我已经使用过maven来构建Java代码。 我正在尝试构建使用gradle的项目:https://github.com/opendistro-for-elasticsearch/anomaly-detection

我按照以下步骤进行操作,并且在构建过程中不断失败。

克隆代码后,

第1步:按照链接中提到的步骤,我首先安装了Java,然后按如下所示设置Java主目录和路径

yum install java-1.8.0-openjdk
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export PATH=$JAVA_HOME/bin:$PATH  

第2步:我尝试使用如下的gradlew构建项目,并最终出现错误

anomaly-detection]# ./gradlew
Starting a Gradle Daemon,1 incompatible Daemon Could not be reused,use --status for details

FAILURE: Build Failed with an exception.

* Where:
Build file '/host/eclipse_back/opendistro/anomaly-detection/build.gradle' line: 55

* What went wrong:
A problem occurred evaluating root project 'opendistro-anomaly-detection'.
> Failed to apply plugin [id 'elasticsearch.esplugin']
   > Could not create plugin of type 'PluginBuildplugin'.
      > Could not generate a decorated class for type PluginBuildplugin.
         > org/elasticsearch/gradle/plugin/PluginPropertiesExtension has been compiled by a more recent version of the Java Runtime (class file version 54.0),this version of the Java Runtime only recognizes class file versions up to 52.0

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD Failed in 8s

为什么失败了?任何帮助表示赞赏!

谢谢,
哈里

解决方法

您需要为gradle设置构建环境以使用最新的Java版本。您可以使用gradle property org.gradle.java.home设置Java版本:

org.gradle.java.home=<path to JDK home>
,

我认为问题在于您使用Java 8,而他们在README中想要使用Java 14。

要从命令行进行构建,请在运行./gradlew之前将JAVA_HOME指向JDK 14

然后应该可以使用以下命令来构建和测试项目:

./gradlew build

编辑

可以检查IDE的配置吗? Gradle JVM是否使用了正确的Java版本?如果您使用的是Intellik,则可以按照以下post进行检查:

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...