2

我一直在寻找解决这个问题的方法,但我似乎无法找到正确的答案。我相信,我有一个独特的情况,因此问题可能更难以解决。
问题的核心是我在运行mvn test命令时收到的错误消息:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:testCompile (default-testCompile) on project DriveServiceFitnesse: Fatal error compiling: java.lang.ClassCastException: com.sun.tools.javac.code.Attribute$Error cannot be cast to com.sun.tools.javac.code.Attribute$Class -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

但是mvn compile没有通过错误。但是因为我需要 mvn test 来生成测试源,所以我的测试实际上并没有工作。我知道这一点,因为当我运行测试时,我收到了这个错误:

    Error:java: java.lang.ClassCastException: 
com.sun.tools.javac.code.Attribute$Error cannot be cast to 
com.sun.tools.javac.code.Attribute$Class

该项目用于编译和运行没有问题。当我尝试将我的项目从 Maven 转换为 Gradle 时,出现了这个问题。我遇到了类似的问题,所以我关闭了分支并拉下了我原来的工作代码/项目,现在我似乎无法修复它。

对此问题的任何帮助将不胜感激。如果可能有帮助,我将发布我的 pom.xml 文件。

*编辑:根据我在收到的堆栈跟踪消息中粘贴的建议:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:testCompile (default-testCompile) on project DriveServiceFitnesse: Fatal error compiling: java.lang.ClassCastException: com.sun.tools.javac.code.Attribute$Error cannot be cast to com.sun.tools.javac.code.Attribute$Class -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:testCompile (default-testCompile) on project DriveServiceFitnesse: Fatal error compiling
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Fatal error compiling
        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:836)
        at org.apache.maven.plugin.compiler.TestCompilerMojo.execute(TestCompilerMojo.java:153)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
4

3 回答 3

1

修复了这个错误。是我的疏忽。问题是由于某种原因,我使用“项目结构”(在 intellij 中)导入的本地 jar 不知何故过期了,即该库仍在列出,但没有被正确地拉入项目中。我删除了引用并重新导入,事情似乎奏效了……叹息。

于 2015-07-24T17:41:47.680 回答
0

我尝试了多种解决方案来查找问题的根本原因,并观察到我的机器编译类的时间比平时要长,因此我们尝试增加配置中的 maxmem 选项。

我已将编译器插件 maxmem 选项从1024m 更改为 2048m,这解决了问题

于 2020-06-24T13:30:30.467 回答
0

对我来说,这个问题是由于我试图在我的 pom.xml 中使用“默认 maven 配置文件”以及另一个 e2e 测试配置文件引起的。我切换回普通的 pom,它现在可以工作了。仍然不确定真正的原因。

于 2021-07-06T20:57:34.220 回答