Java 23项目运行PMD报错Unsupported class file major version 67如何解决?
解决PMD不支持Java 23类文件版本的问题
错误原因
你遇到的Unsupported class file major version 67错误,是因为当前Maven PMD插件3.25.0集成的PMD 7.3.0依赖的ASM库版本过低,无法识别Java 23对应的类文件主版本号67。
解决方案
方案1:升级Maven PMD插件到最新稳定版
新版本的Maven PMD插件会集成支持更高Java版本的PMD核心库,直接更新插件版本即可:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>3.26.0</version> <!-- 可替换为最新稳定版 --> <configuration> <outputDirectory>target/reports/pmd</outputDirectory> <skipEmptyReport>false</skipEmptyReport> </configuration> </plugin>
方案2:指定支持Java 23的PMD核心版本
若不想升级插件,可在插件依赖中单独指定支持Java 23的PMD版本(如7.4.0及以上):
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>3.25.0</version> <configuration> <outputDirectory>target/reports/pmd</outputDirectory> <skipEmptyReport>false</skipEmptyReport> </configuration> <dependencies> <dependency> <groupId>net.sourceforge.pmd</groupId> <artifactId>pmd-java</artifactId> <version>7.4.0</version> <!-- 或更高支持Java23的版本 --> </dependency> </dependencies> </plugin>
方案3:升级ASM依赖库
ASM 9.6及以上版本支持Java 23的类文件格式,可单独升级插件的ASM依赖:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>3.25.0</version> <configuration> <outputDirectory>target/reports/pmd</outputDirectory> <skipEmptyReport>false</skipEmptyReport> </configuration> <dependencies> <dependency> <groupId>org.ow2.asm</groupId> <artifactId>asm</artifactId> <version>9.6</version> </dependency> <dependency> <groupId>org.ow2.asm</groupId> <artifactId>asm-tree</artifactId> <version>9.6</version> </dependency> </dependencies> </plugin>
内容的提问来源于stack exchange,提问作者PatPanda
相关产品推荐
相关产品推荐

