【问题标题】:Exclude findbugs plugin from root pom从根 pom 中排除 findbugs 插件
【发布时间】:2016-08-09 12:57:27
【问题描述】:

我有一个根 pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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>packaging</groupId>
<artifactId>profiles</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>1.2</version>
            <configuration>
                <findbugsXmlOutput>true</findbugsXmlOutput>
                <findbugsXmlWithMessages>true</findbugsXmlWithMessages>
                <xmlOutput>true</xmlOutput>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <modules>
            <module>../common-core</module>
            <module>../spark-monitoring-module</module>
            <module>../mass-analytics-connector-module</module>
            <!--<module>../global-aggregation-job</module>-->
            <module>../location-aggregation-job</module>
            <module>../bdr-aggregation-job</module>
            <module>../activities-aggregation-job</module>
            <module>../recovery-aggregation-job</module>
            <module>../link-analysis-aggregation-job</module>
            <module>../spark-streaming-module</module>
            <module>../coordinates-to-mgrs-converter</module>
        </modules>
    </profile>
    <profile>
        <id>all</id>
        <modules>
            <module>../common-core</module>             
            <module>../spark-monitoring-module</module>
            <module>../mass-analytics-connector-module</module>
            <module>../global-aggregation-job</module>
            <module>../location-aggregation-job</module>
            <module>../bdr-aggregation-job</module>
            <module>../activities-aggregation-job</module>
            <module>../recovery-aggregation-job</module>
            <module>../link-analysis-aggregation-job</module>
            <module>../spark-streaming-module</module>
            <module>../parquet-writer-sim</module>
            <module>../coordinates-to-mgrs-converter</module>
        </modules>
    </profile>
    <profile>
        <id>act</id>
        <modules>
            <module>../common-core</module>
            <module>../bdr-aggregation-job</module>
            <module>../activities-aggregation-job</module>
        </modules>
    </profile>
</profiles>

当我在 Jenkins 中运行 mvn clean install findbugs:findbugs 时,它会创建每个模块的 findbugsXml.xml 并且由于配置文件模块(不包含任何代码)而导致当前作业失败。我不希望 finbugs 插件在配置文件 pom(它是根 pom)上运行,如何从 findbugs 插件中排除配置文件?

【问题讨论】:

    标签: java jenkins maven-3


    【解决方案1】:

    真的有两个变化。

    1) 将您的插件部分(如上构建)移动到 pluginManagement 部分,如下所示: 我已经更新了你的插件详细信息,因为它已经很旧了。

    <pluginManagement>
       <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.4</version>
                    <executions>
                        <execution>
                            <id>check</id>
                            <phase>package</phase>
                            <goals>
                                <goal>check</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <xmlOutput>true</xmlOutput>
                        <xmlOutputDirectory>findbugsreports</xmlOutputDirectory>
                        <findbugsXmlOutput>true</findbugsXmlOutput>
                        <findbugsXmlOutputDirectory>target/site</findbugsXmlOutputDirectory>
                        <failOnError>false</failOnError>
                    </configuration>
                </plugin>
        </plugins>
    </pluginManagement>
    
    1. 在需要查找错误的 pom 中,有一个最小构建部分:
     <build>
      <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
            </plugin>
       </plugins>
    </build>
    

    如果您需要更改一般属性,则在根 pom 中进行,如果您需要在所涉及的单个子 POM 中更改特定属性。 这种方法的好处是您可以在最高级别管理您的插件,并将它们包含在您认为适合子级别的位置。除非绝对必要,否则这会减少多种配置。

    【讨论】:

    • 有没有办法在每个模块中不添加这些行,我想将它应用于除根模块(配置文件)之外的所有模块?
    • 不抱歉,它应该是这样工作的,请查看完整的 stackoverflow 回复,这里提到; stackoverflow.com/questions/10483180/…
    • 您是否从根 pom 中删除了构建部分?该插件中可能还有一些假设某些东西 - 例如在当前目录中运行。请检查 root pom 1st。
    • 是的,我把它放在插件管理标签下(正在构建中)
    • 不确定问题出在哪里,但这是一个相当老的 findbugs 版本,也许是一些问题。我尝试了 mvn 3 和一个小设置,它在这里运行得很好。将使用最新配置更新我的答案。
    猜你喜欢
    • 1970-01-01
    • 2018-04-12
    • 2011-06-17
    • 2021-09-28
    • 2014-03-29
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    相关资源
    最近更新 更多