代码之家  ›  专栏  ›  技术社区  ›  Jonathan S. Fisher

如何让pmd maven插件跳过生成的源代码?

  •  0
  • Jonathan S. Fisher  · 技术社区  · 7 年前

    所以我正在使用maven插件创建一个maven插件。maven插件中的helpmojo生成一个java源文件。

    不幸的是,PMD发现了这一点并对此抱怨不已。有没有办法让pmd只忽略一个源文件?谢谢!

    Maven PMD配置:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <executions>
                    <execution>
                        <id>pmd-verify</id>
                        <goals>
                            <goal>check</goal>
                            <goal>cpd-check</goal>
                        </goals>
                        <configuration>
                            <printFailingErrors>true</printFailingErrors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   adangel    7 年前

    生成的源通常最终(使用maven)位于 target/generated-sources ,对于maven插件 target/generated-sources/plugin 是的。

    您可以排除这些完整的目录 excludeRoots ,例如

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <executions>
                <execution>
                    <id>pmd-verify</id>
                    <goals>
                        <goal>check</goal>
                        <goal>cpd-check</goal>
                    </goals>
                    <configuration>
                        <printFailingErrors>true</printFailingErrors>
                        <excludeRoots>
                            <excludeRoot>target/generated-sources/plugin</excludeRoot>
                        </excludeRoots>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    

    还有一个基于文件的 exclude 选择。