groovy BUG!“语义分析”阶段出现异常

4jb9z9bj  于 2023-06-21  发布在  其他
关注(0)|答案(9)|浏览(565)

我有一个使用Gradle 1.10和jdk1.8的1.1.7 spring-boot应用程序。我使用Groovy/Spock进行测试,它有两个依赖项-使用Apache Maven 3.1.1和jdk 1.8构建的jar。我构建了jar,然后将它们复制到/lib目录中。然后我试着用“Gradle clean build "来构建。
以下是我的gradle文件的一部分:

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'maven'

project.ext {
    springBootVersion = '1.1.7.RELEASE'
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
buildscript {
    repositories {
        flatDir {
            dirs "$rootProject.projectDir/libs"
        }
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
        maven { url "http://repo.spring.io/libs-milestone" }
        maven { url "http://repo.spring.io/libs-snapshot" }
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
  testCompile('org.spockframework:spock-core:1.0-groovy-2.0') {
    exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}

  testCompile('org.spockframework:spock-spring:1.0-groovy-2.0') {
    exclude group: 'org.spockframework', module: 'spock-core'
    exclude group: 'org.spockframework', module: 'spring-beans'
    exclude group: 'org.spockframework', module: 'spring-test'
    exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}

   testCompile("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
    testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.7+')
    testCompile("junit:junit")
    }
}

jacocoTestReport {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

无论从命令行还是IntelliJ构建,我都会得到以下错误:

Executing org.gradle.api.internal.tasks.compile.ApiGroovyCompiler@5474aad4 in compiler daemon.
Exception executing org.gradle.api.internal.tasks.compile.ApiGroovyCompiler@5474aad4 in compiler daemon: BUG! exception in phase 'semantic analysis' in source unit '/Users/David/projects/.../controller/AboutControllerTest.groovy' sun.reflect.annotation.TypeNotPresentExceptionProxy.
:compileTestGroovy FAILED

下面是stacktrace:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileTestGroovy'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:62)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
        at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:158)
        at org.gradle.internal.Factories$1.create(Factories.java:22)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:52)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:155)
        at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:36)
        at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:103)
        at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:97)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:97)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:102)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:32)
        at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:77)
        at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:47)
        at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:51)
        at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:28)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:43)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:170)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
        at org.gradle.launcher.Main.doAction(Main.java:33)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: BUG! exception in phase 'semantic analysis' in source unit '/Users/David/projects/.../src/test/groovy/.../controller/AboutControllerTest.groovy' sun.reflect.annotation.TypeNotPresentExceptionProxy
        at org.gradle.api.internal.tasks.compile.ApiGroovyCompiler.execute(ApiGroovyCompiler.java:152)
        at org.gradle.api.internal.tasks.compile.ApiGroovyCompiler.execute(ApiGroovyCompiler.java:51)
        at org.gradle.api.internal.tasks.compile.daemon.CompilerDaemonServer.execute(CompilerDaemonServer.java:53)
        at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
        at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:360)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
        at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
        ... 8 more

这没有什么错,或者任何其他测试,因为它在几个月内没有改变。实际上,问题似乎是在我将这两个jar文件添加到项目时就开始了。但是,我还没有能够找到一个答案,这个特定的错误消息的任何地方。

ogq8wdun

ogq8wdun1#

我今天遇到了这个BUG! exception in phase 'semantic analysis' in source unit '...'问题,升级gradle(在评论中提到)不起作用。gradle clean也不工作。
对我有效的是清理gradle缓存:
rm -rf $HOME/.gradle/caches/
和项目gradle目录
rm -rf $PROJECT/.gradle/caches/ && rm -rf $PROJECT/build/
相关如何强制gradle重新下载依赖项?

laximzn5

laximzn52#

我只在使用Java 11 JVM时看到相同的错误:

$ gradle -v

------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------

Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          11 (Oracle Corporation 11+28)
OS:           Mac OS X 10.14.3 x86_64

当我回到Java 1.8时,错误消失了(我改变了JAVA_HOME):

$ gradle -v

------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------

Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_191 (Oracle Corporation 25.191-b12)
OS:           Mac OS X 10.14.3 x86_64
tp5buhyn

tp5buhyn3#

我的问题是我使用Java 16和Gradle 6.5。但是Gradle 6.5不支持Java 16。我需要升级到7.0。我通过在这一行中更改gradle/wrapper/gradle-wrapper.properties来做到这一点:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
vdgimpew

vdgimpew4#

在将SAP hybris从版本6.6(java 8)迁移到2005(java 11)时遇到了同样的问题。在ant clean all和recipe安装时遇到此问题。
错误:

hybris/bin/modules/text-field-configurator-template/textfieldconfiguratortemplateocctests/testsrc/de/hybris/platform/textfieldconfiguratortemplateocctests/controllers/ProductTextfieldConfiguratorControllerTest.groovy' null

**解决方案:**通过在config/ www.example.com中注解/删除以下属性解决了问题local.properties

build.parallel=true
r8uurelv

r8uurelv5#

我认为这是由于java版本太高,或者我们可以说gradle版本太低。
所以我只使用更高版本的Gradle。我认为这比将JDK版本更改为1.8更好。
我的配置(我已经有了gradle 6.5,我想6.x可能会满足):

只需将android\gradle\wrapper\gradle-wrapper.properties中的gradle版本更改为6.5

jm81lzqq

jm81lzqq6#

当我使用groovy Spock测试将我的项目从JDK 8升级到JDK 11时,就发生了这种情况。
修复是将spock版本升级到1.3-groovy-2.5,将groovy版本升级到2.5.3,用于我的gradle依赖项。
此外,在我的例子中,我必须将jaxws和jaxb的实现添加到我的依赖项中,因为它们已经从JDK 11中删除了:

implementation 'com.sun.xml.ws:jaxws-ri:2.3.2'
    implementation 'com.sun.xml.bind:jaxb-impl:2.4.0-b180830.0438'
sqougxex

sqougxex7#

您可以检查Gradle版本是否与Java版本兼容
Gradle compatibility
我将我的Gradle版本升级到与我的Java版本兼容的最新版本,错误就消失了。

tktrz96b

tktrz96b8#

在我的例子中,原因是IntellijIdea变量生成。
示例:Idea生成List<@NotNull UUID> locationIds而不是List<UUID> locationIds
Groovy编译无法处理泛型括号内的此@NotNull注解

juzqafwq

juzqafwq9#

确保build. gradle中的build:gradle版本与www.example.com中的distributionUrlgradle-wrapper.properties兼容

相关问题