0

I have a root 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>

When I run mvn clean install findbugs:findbugs in Jenkins , it creates the findbugsXml.xml of every module and fails the current job because of profiles module (which doesn't contain any code). I don't want the finbugs plugin to run on the profiles pom (it is the root pom), how do I exclude profiles from the findbugs plugin?

user2199630
  • 203
  • 1
  • 2
  • 12

1 Answers1

2

Two changes really.

1) Move your plugin section (build above) to a pluginManagement section,like so: I have updated your plugin details, as it was quite old.

<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. In the poms where you need a find bugs, have a minmal build section:
 <build>
  <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
        </plugin>
   </plugins>
</build>

If you need to change a general property then you do it in the root pom, if you need to change a specific property to it in the single child POM involved. The benefits of such approach is that you manage your plugins at the highlest level possible and include them where you feel fit at the child level. This cuts out multiple configurations, except where absolutely necessary.

PeterS
  • 2,818
  • 23
  • 36
  • Is there a way to do it without adding those lines in each module, i want to apply it on all modules except for the root module (profiles)? – user2199630 Aug 09 '16 at 13:25
  • No sorry, that is really how it should work, please check a full stackoverflow reply, mentioned here; http://stackoverflow.com/questions/10483180/maven-what-is-pluginmanagement – PeterS Aug 09 '16 at 13:52
  • Did you remove the build part from the root pom? There may also be something in that plugin that is assuming something - such as run in current dir. Please check the root pom 1st. – PeterS Aug 09 '16 at 14:27
  • Yes, i put it under plugin managment tag (which is under build) – user2199630 Aug 09 '16 at 14:29
  • Not sure what the problem is, but that is quite an old version of findbugs, maybe it is some issue with that. i tried mvn 3 and a small setup and it ran through just fine here. Will update my answer with latest config. – PeterS Aug 09 '16 at 15:13