Gradle 为 java 构建 Apache POI 包的问题

问题描述 投票:0回答:1

以前使用 Apache 包时,它们包含了 jar 文件,我所要做的就是通过构建路径将它们导入。

使用 Apache POI (5.2.4-20230921),它现在使用 Gradle 来构建 jar。

我尝试通过导入-->现有 Gradle 项目并选择根目录在 Eclipse (2022-03) 中构建 POI。当我这样做时,我得到以下信息:

提供的分阶段操作因异常而失败。一个问题 发生配置项目“:poi”。评估时出现问题 项目“:poi”。无法计算任务价值 ':poi:compileTestJava' 属性 'javaCompiler'。没有匹配的工具链 找到所请求的规范:{languageVersion=8,供应商=any, 对于 x86_64 上的 WINDOWS,实现 = 特定于供应商}。本地没有 安装的工具链匹配和工具链下载存储库有 没有被配置。 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
java gradle apache-poi
1个回答
0
投票

我通过编辑 build.gradle 文件让它工作。如果检测不起作用,则默认为 8。

我改变这一行:

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

对此:

jdkVersion = (21) as int

在 build.gradle 中,它运行了。当然,如果您遇到相同的错误或可以解决自动检测问题,则必须将其更改为您正在运行的任何版本。

© www.soinside.com 2019 - 2024. All rights reserved.