Maven skip site/reporting for module
-
11-06-2021 - |
Question
I have a multi-module project and in the parent pom, I have several reporting plug-ins defined. Some of the modules contain code that does not need to have the reporting plugins run against them and I do not need them included in the generated site. Is there a way I can tell Maven to ignore them at the parent pom level?
Update:
Based on ajozwik's answer I added the skip configuration. My POMs now look like the following...
parent/pom.xml<modules>
<module>service</module>
<module>client</module>
</modules>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.4.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<formats>
<format>html</format>
</formats>
</configuration>
</plugin>
</plugins>
</reporting>
client/pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.1</version>
<configuration>
<skip>true</skip>
<skipDeploy>true</skipDeploy>
</configuration>
</plugin>
</plugins>
</build>
When I execute:
mvn clean package site
The build succeeds and the client's target directory does not contain the generated site. When I run:
mvn clean package site site-stage
In order to stage the site, it stages the site correctly. Without the skipDeploy tag, the staging would fail...
Solution
Have you tried (in child pom)?:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
Update. You can use property to redefine default behavior. Keep your children poms simple.
In parent pom set (pluginManagement or plugins section)
<properties>
<maven-site-plugin.skip>false</maven-site-plugin.skip>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.1</version>
<configuration>
<skip>${maven-site-plugin.skip}</skip>
</configuration>
</plugin>
In parent pom just redefine maven-site-plugin.skip
:
<properties>
<maven-site-plugin.skip>true</maven-site-plugin.skip>
</properties>
OTHER TIPS
You can also ignore report generation on the command line:
mvn -DgenerateReports=false package
You can also ignore report generation with:
mvn -Dmaven.site.skip=true clean install for example
To get coverage running for Sonar, Jacoco can also be configured like this;
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
This will result in no /target/site/jacoco/jacoco.xml
file for your project, now the jacoco.exec
file will be used for covarage will process as expected