Java 17 gradle 7.3.3 Intellij 无法将 org.gradle.api.file.Directory 转换为 java.io.File

发布于 2025-01-12 10:19:55 字数 3516 浏览 0 评论 0原文

我正在将项目从 Java 8 迁移到更新版本。 我没有使用模块信息。

springBootVersion=2.5.7
springCloudVersion=2020.0.5

我在 build 期间在 Intellij 中遇到错误:

Cannot cast object 'property(org.gradle.api.file.Directory, undefined)' with class 'org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar' to class 'java.io.File'
* Exception is:
com.intellij.openapi.externalSystem.model.ExternalSystemException: Cannot cast object 'property(org.gradle.api.file.Directory, undefined)' with class 'org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar' to class 'java.io.File'

使用 gradle-7.3.3 时出现此问题, 当更改为 gradle-7.4 时,问题更改为:

Cannot query the value of this property because it has no value available.

在 gradle 7.3 上,问题是:

class org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar cannot be cast to class java.io.File (org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @6a4f787b; java.io.File is in module java.base of loader 'bootstrap')
class org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar cannot be cast to class java.io.File (org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @6a4f787b; java.io.File is in module java.base of loader 'bootstrap')

我认为问题来自于这个之前工作正常的 gradle 块(idea 部分):

afterEvaluate {
    contracts {
        baseClassForTests = "(...).contract.ContractBaseSpec"
        basePackageForTests = '(...).contract.tests'
        //targetFramework = TestFramework.SPOCK some other error here
        testMode = 'EXPLICIT'
        baseClassMappings {
            baseClassMapping('.*event.*', '(...).contract.EventContractBaseSpec')
        }
    }

    idea {
        module {
            testSourceDirs += project.contracts.generatedTestSourcesDir
            generatedSourceDirs += project.contracts.generatedTestSourcesDir
        }
    }
}

之后评论它 - 构建还可以。

Intellij 2022.1 EAP, 2021年3月2日也是如此。

IntelliJ的中的Java版本设置项目设置没有什么区别,我尝试了:java 11java 17

构建工具-gradle JVMjava版本设置相同。

https://docs.gradle.org/current/userguide/compatibility.html< /a> Java 17gradle 7.3 兼容。

从终端和詹金斯运行我看到其他问题:

sdk use java 17.0.2-open

Using java version 17.0.2-open in this shell.

 ./gradlew --version

------------------------------------------------------------
Gradle 7.3
------------------------------------------------------------


 ./gradlew clean build

问题:

 > BUG! exception in phase 'semantic analysis' in source unit '(.some-path-here...)/contract/ClientBuilder.groovy' Unsupported class file major version 61

Stacktrace: https:// gradle中的pastebin.pl/view/1449e795

jacoco {
    toolVersion = "0.8.7"
}

至于这个问题,将groovy从3.0.3更新为3.0.9 修复了它并显示了另一个问题。 仍然为什么 IntelliJ 显示不同的问题?

I am migrating project from Java 8 to newer version.
I am not using module info.

springBootVersion=2.5.7
springCloudVersion=2020.0.5

I have an error in Intellij during build:

Cannot cast object 'property(org.gradle.api.file.Directory, undefined)' with class 'org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar' to class 'java.io.File'
* Exception is:
com.intellij.openapi.externalSystem.model.ExternalSystemException: Cannot cast object 'property(org.gradle.api.file.Directory, undefined)' with class 'org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar' to class 'java.io.File'

This issue occurs while using gradle-7.3.3,
when changed to gradle-7.4 issue changes to:

Cannot query the value of this property because it has no value available.

On gradle 7.3 the issue is:

class org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar cannot be cast to class java.io.File (org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @6a4f787b; java.io.File is in module java.base of loader 'bootstrap')
class org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar cannot be cast to class java.io.File (org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @6a4f787b; java.io.File is in module java.base of loader 'bootstrap')

I think the issue comes from this gradle block (idea part) that worked fine before:

afterEvaluate {
    contracts {
        baseClassForTests = "(...).contract.ContractBaseSpec"
        basePackageForTests = '(...).contract.tests'
        //targetFramework = TestFramework.SPOCK some other error here
        testMode = 'EXPLICIT'
        baseClassMappings {
            baseClassMapping('.*event.*', '(...).contract.EventContractBaseSpec')
        }
    }

    idea {
        module {
            testSourceDirs += project.contracts.generatedTestSourcesDir
            generatedSourceDirs += project.contracts.generatedTestSourcesDir
        }
    }
}

After commenting it - build is ok.

Intellij 2022.1 EAP,
the same in 2021.3.2.

Java version setting in IntelliJ's Project setting does not make difference, I tried both: java 11 and java 17.

The same with build tools - gradle JVM java version setting.

As of https://docs.gradle.org/current/userguide/compatibility.html
Java 17 is compatible from gradle 7.3.

Running from terminal and from jenkins i see other issue:

sdk use java 17.0.2-open

Using java version 17.0.2-open in this shell.

 ./gradlew --version

------------------------------------------------------------
Gradle 7.3
------------------------------------------------------------


 ./gradlew clean build

Issue:

 > BUG! exception in phase 'semantic analysis' in source unit '(.some-path-here...)/contract/ClientBuilder.groovy' Unsupported class file major version 61

Stacktrace: https://pastebin.pl/view/1449e795

in gradle:

jacoco {
    toolVersion = "0.8.7"
}

as for this issue updating groovy from 3.0.3 to 3.0.9 fixes it and shows another issue.
Still why IntelliJ shows different issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文