简体   繁体   English

来自Java 11项目的Maven-pmd-plugin的UnsupportedClassVersionError

[英]UnsupportedClassVersionError from maven-pmd-plugin for java 11 project

We are migrating our java 8 projects to java 11. JAVA_HOME still points to java 8 but the first project to be migrated compiles in java 11 and the unit tests run just fine. 我们正在将Java 8项目迁移到Java11。JAVA_HOME仍然指向Java 8,但是第一个要迁移的项目在Java 11中编译,并且单元测试运行良好。

The maven-compiler-plugin and the toolchain are defined as in this question . maven-compiler-plugin和工具链的定义如本问题所述 Maven version is 3.5.0. Maven版本是3.5.0。

When i run 当我跑步

mvn verify

I get the following error: 我收到以下错误:

Failed to execute goal org.apache.maven.plugins:maven-pmd-plugin:3.11.0:
pmd (pmd) on project <yourproject>: 
  Execution pmd of goal org.apache.maven.plugins:maven-pmd-plugin:3.11.0:
  pmd failed: An API incompatibility was encountered while executing 
  org.apache.maven.plugins:maven-pmd-plugin:3.11.0:pmd: 
    java.lang.UnsupportedClassVersionError: 
       <Yourclass> has been compiled by a more recent version of the Java Runtime 
       (class file version 55.0), this version of the Java Runtime only recognizes 
       class file versions up to 52.0    //(indentation added for readability)

I understand that the classes were compiled using java 11 (as intended) and that maven runs on java 8 because that is what JAVA_HOME points to. 我知道这些类是使用Java 11编译的(按预期方式),并且maven在Java 8上运行,因为这就是JAVA_HOME所指向的。 But why does that trip up the pmd-plugin ? 但是,为什么那会触发pmd-plugin呢? It is supposed to check the source code, never mind the compiled classes. 应该检查源代码,不要管编译的类。

Is there a way around this, short of setting JAVA_HOME to 11? 除了将JAVA_HOME设置为11以外,还有其他解决方法吗?

Actually, PMD does care about compiled classes for type resolution. 实际上,PMD确实关心用于类型解析的已编译类。

PMD is able to check variable types, method return types, and so on for usage in it's analysis. PMD能够检查变量类型,方法返回类型等,以用于其分析。 To do so, PMD uses the compiled classes and complete dependencies classpath. 为此,PMD使用编译的类和完整的依赖项类路径。

You can disable this through the plugin's configuration by setting the typeResolution property to false , but be warned , several rules rely on this information, and when not available work on a best effort basis, which means you will get more false positives / negatives in the analysis. 您可以通过将插件的配置typeResolution属性设置为false来禁用此功能,但是要注意 ,一些规则依赖于此信息,并且在无法尽力而为的情况下,这意味着您会在分析。

PMD's analysis quality is significantly hampered by not using type resolution. 不使用类型分辨率会极大地妨碍PMD的分析质量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM