当前位置: 首页 > 知识库问答 >
问题:

PMD插件因Java 14失败:不支持的targetJdk

漆雕奇
2023-03-14

我试图有一个pom.xml文件与PMD插件集成到构建阶段。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>group</groupId>
    <artifactId>artifact</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>


    <properties>
        <maven.compiler.source>14</maven.compiler.source>
        <maven.compiler.target>14</maven.compiler.target>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <pmd.plugin.version>3.13.0</pmd.plugin.version>
    </properties>

    <dependencies>

    </dependencies>


    <reporting>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
            </plugin>

        </plugins>
    </reporting>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-pmd-plugin</artifactId>
                    <version>${pmd.plugin.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <configuration>
                    <!-- failOnViolation is actually true by default, but can be disabled -->
                    <failOnViolation>true</failOnViolation>
                    <!-- printFailingErrors is pretty useful -->
                    <printFailingErrors>true</printFailingErrors>
                    <targetJdk>14</targetJdk>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

mvn clean安装失败

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-pmd-plugin:3.13.0:pmd (pmd) on project notes-service: Execution pmd of goal org.apache.maven.plugins:maven-pmd-plugin:3.13.0:pmd failed: org.apache.maven.reporting.MavenR
eportException: Unsupported targetJdk value '14'. -> [Help 1]

https://stackoverflow.com/a/2033299/1839360为pmd-java添加了一个依赖项-它不起作用。我试了两个版本https://mvnrepository.com/artifact/net.sourceforge.pmd/pmd-java/6.21.0 https://mvnrepository.com/artifact/net.sourceforge.pmd/pmd-java/6.23.0

用最新版本,有错误

Exception in thread "main" java.util.ServiceConfigurationError: net.sourceforge.pmd.lang.Language: Provider net.sourceforge.pmd.lang.java.JavaLanguageModule could not be instantiated
        at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:584)
        at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:806)
        at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:724)
        at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1396)
        at net.sourceforge.pmd.lang.LanguageRegistry.<init>(LanguageRegistry.java:35)
        at net.sourceforge.pmd.lang.LanguageRegistry.<clinit>(LanguageRegistry.java:24)
        at org.apache.maven.plugins.pmd.PmdReport.getPMDConfiguration(PmdReport.java:723)
        at org.apache.maven.plugins.pmd.PmdReport.executePmd(PmdReport.java:411)
        at org.apache.maven.plugins.pmd.PmdReport.executePmdWithClassloader(PmdReport.java:376)
        at org.apache.maven.plugins.pmd.PmdReport.canGenerateReport(PmdReport.java:350)
        at org.apache.maven.reporting.AbstractMavenReport.execute(AbstractMavenReport.java:120)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
        at org.apache.maven.lifecycle.internal.MojoExecutor.executeForkedExecutions(MojoExecutor.java:355)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:200)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
Caused by: java.lang.NoSuchMethodError: 'void net.sourceforge.pmd.lang.metrics.internal.AbstractLanguageMetricsProvider.<init>(java.lang.Class, java.lang.Class)'
        at net.sourceforge.pmd.lang.java.JavaLanguageHandler$JavaMetricsProvider.<init>(JavaLanguageHandler.java:48)
        at net.sourceforge.pmd.lang.java.AbstractJavaHandler.<init>(AbstractJavaHandler.java:53)
        at net.sourceforge.pmd.lang.java.JavaLanguageHandler.<init>(JavaLanguageHandler.java:35)
        at net.sourceforge.pmd.lang.java.JavaLanguageHandler.<init>(JavaLanguageHandler.java:32)
        at net.sourceforge.pmd.lang.java.JavaLanguageModule.<init>(JavaLanguageModule.java:20)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
        at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:782)
        ... 35 more


共有1个答案

程墨竹
2023-03-14

我必须添加这些依赖项

<dependencies>
    <dependency>
        <groupId>net.sourceforge.pmd</groupId>
        <artifactId>pmd-java</artifactId>
        <version>6.23.0</version>
    </dependency>

    <dependency>
        <groupId>net.sourceforge.pmd</groupId>
        <artifactId>pmd-core</artifactId>
        <version>6.23.0</version>
        </dependency>
</dependencies>

整个绒球.xml是

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>group</groupId>
    <artifactId>artifact</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>


    <properties>
        <maven.compiler.source>14</maven.compiler.source>
        <maven.compiler.target>14</maven.compiler.target>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <pmd.plugin.version>3.13.0</pmd.plugin.version>
    </properties>

    <dependencies>

    </dependencies>


    <reporting>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
            </plugin>

        </plugins>
    </reporting>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-pmd-plugin</artifactId>
                    <version>${pmd.plugin.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <configuration>
                    <!-- failOnViolation is actually true by default, but can be disabled -->
                    <failOnViolation>true</failOnViolation>
                    <!-- printFailingErrors is pretty useful -->
                    <printFailingErrors>true</printFailingErrors>
                    <targetJdk>14</targetJdk>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>

                <dependencies>
                    <!-- https://mvnrepository.com/artifact/net.sourceforge.pmd/pmd-java -->
                    <dependency>
                        <groupId>net.sourceforge.pmd</groupId>
                        <artifactId>pmd-java</artifactId>
                        <version>6.23.0</version>
                    </dependency>

                    <!-- https://mvnrepository.com/artifact/net.sourceforge.pmd/pmd-core -->
                    <dependency>
                        <groupId>net.sourceforge.pmd</groupId>
                        <artifactId>pmd-core</artifactId>
                        <version>6.23.0</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>
 类似资料:
  • 我试图添加eclipse pmd插件最终出现以下错误。 知道哪里出问题了吗?

  • 这是一个已知的问题吗?有解决办法吗?

  • 将Android Studio从V2.5更新到V3.1.2后,所有项目都无法构建 我已经清理了我的项目,重新启动了Android Studio,并重新启动了机器。我甚至删除了项目中的文件夹。它是用子目录4.1重新创建的-尝试在删除后构建。 Gradle-Wrapper.属性: 堆栈跟踪:

  • Gradle同步失败:不支持的类文件主版本60(13 m 44 s 731 ms) 无法为初始化脚本'C:\User\umer\AppData\Local\Temp\ijresolvers.gradle'打开初始化泛型类缓存(C:\User\umer.gradle\cache\6.7.1\script\c6td7o6d0dhgcyioq91fpl38q)。 缺陷源单元“BuildScript”中的

  • 我在Linux (Arch Linux)上,用的是Android Studio 2.3.1 在Android Studio中创建新的空项目时,我得到错误消息: 似乎爪哇版本有一些东西。我已经安装了 openjdk-8,并且还尝试了 Oracle JDK 版本 8(也尝试了版本 7)。 我尝试过的事情: > < li> 使用已安装的gradle或Android Studio附带的gradle 删除

  • Tabris.js API主要是一个UI/控件的库,还有一些额外的受浏览器启发的API。为了提供它们不涉及的功能,Tabris.js可以使用Apache Cordova插件进行扩展。 Cordova插件的JavaScript API文档在Tabris.js中也是有效的,只有一个小例外:在访问插件API之前,无需监听deviceready事件。当加载应用程序主模块时,所有插件都将准备就绪。 默认插件