Gradle为Java构建Apache POI包的问题

bf1o4zei  于 2023-11-18  发布在  Java
关注(0)|答案(1)|浏览(225)

以前使用Apache包时,它们包含jar文件,我所要做的就是通过构建路径将它们导入。
在Apache POI(5.2.4-20230921)中,它现在使用Gradle来构建jar。
我尝试在Eclipse(2022-03)中构建POI,方法是导入-->Existing Gradle Project并选择根目录。当我这样做时,我得到以下内容:
提供的分阶段操作失败,并出现异常。配置项目“:poi”时出现问题。评估项目“:poi”时出现问题。无法计算任务":poi:compileTestJava“属性”javaTester“的值。未找到与请求的规范匹配的工具链:{languageVersion=8,vendor=any,implementation=vendor-specific} for Windows on x86_64。没有本地安装的工具链匹配,并且尚未配置工具链下载存储库。poi-src-5.2.4- 20230921-5.2.4第0行Gradle错误标记
当我在命令行上尝试时,我得到了同样的东西。我在“https://docs.gradle.org/8.4/userguide/toolchains.html#sec:auto_detection“上查找了工具链信息,但没有任何帮助。运行--debug和--stacktrace给了我一堆对我来说意义不大的额外信息。
我没有从Apache更改build.gradle,但这里是工具链行:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(jdkVersion)
        if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor)
    }
    withJavadocJar()
    withSourcesJar()
}

字符串
我从来没有使用过Gradle之前,所以这可能是一些简单的东西.我使用的java 21.0.1 2023-10-17 LTS,这是今天下载并安装.它也没有与我以前的版本工作.
下载最新版本的Gradle并使用最新的Java和Apache包应该是一个非常无缝的过程。
为了解决第一条评论,我将gradle放入poi文件夹并运行gradle.bat。下面是命令和输出:

poi-src-5.2.4-20230921-5.2.4>gradle.bat
Configuration on demand is an incubating feature.

> Configure project :
Trying to override old definition of datatype junit

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\x\eclipse-workspace\poi-src-5.2.4-20230921-5.2.4\poi\build.gradle' line: 82

* What went wrong:
A problem occurred evaluating project ':poi'.
> Failed to calculate the value of task ':poi:compileTestJava' property 'javaCompiler'.
   > No matching toolchains found for requested specification: {languageVersion=8, vendor=any, implementation=vendor-specific} for WINDOWS on x86_64.
      > No locally installed toolchains match and toolchain download repositories have not been configured.

* Try:
> Learn more about toolchain auto-detection at https://docs.gradle.org/8.4/userguide/toolchains.html#sec:auto_detection.
> Learn more about toolchain repositories at https://docs.gradle.org/8.4/userguide/toolchains.html#sub:download_repositories.
> 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.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.4/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 1s

qcuzuvrc

qcuzuvrc1#

我通过编辑build.gradle文件让它工作。如果检测不起作用,它默认为8。
我改了这条线:

jdkVersion = (project.properties['jdkVersion'] ?: '8') as int

字符串
对此:

jdkVersion = (21) as int


当然,如果你有同样的错误或者可以解决自动检测问题,你必须将它更改为你正在运行的任何版本。

相关问题