首页 > 解决方案 > 使用 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

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

谢谢,
哈利

标签: gradlebuild.gradlegradlew

解决方案


您需要为 gradle 设置构建环境以使用更新的 java 版本。您可以使用gradle 属性 设置 java 版本org.gradle.java.home

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

推荐阅读