【问题标题】:Build the project using gradle使用 gradle 构建项目
【发布时间】:2020-08-31 19:55:09
【问题描述】:

到目前为止,我已经使用 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 build.gradle gradlew


    【解决方案1】:

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

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

    【讨论】:

    • 嗨@Mohamad.K 我安装了jdk 14,然后我尝试了这个并以同样的错误结束,并且说构建文件'/host/eclipse_back/opendistro/anomaly-detection/build.gradle'行:55
    【解决方案2】:

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

    在运行 ./gradlew 之前从命令行设置 JAVA_HOME 以指向 JDK 14

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

    ./gradlew build
    

    编辑

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

    【讨论】:

    • 嗨@flaxel,我安装了jdk 14,然后我尝试了这个并以同样的错误结束
    猜你喜欢
    • 2012-08-01
    • 2014-05-16
    • 2012-06-24
    • 2018-07-09
    • 2016-03-31
    • 2011-10-30
    • 1970-01-01
    • 1970-01-01
    • 2015-04-26
    相关资源
    最近更新 更多