aggregating surefire reports in MultiModule project - java

I have multimodule maven project I want to get aggregated surefire reports . I tried below approach but I dont see aggregated surefire report generated. I could see report generated for individual modules.
I have added below plugin configuration in indvidual Modules (packaging jar)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.22.0</version>
</dependency>
</dependencies>
<configuration>
<useManifestOnlyJar>false</useManifestOnlyJar>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
</plugin>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<inherited>false</inherited>
<configuration>
<aggregate>true</aggregate>
<linkXRef>true</linkXRef>
</configuration>
</plugin>
</plugins>
</reporting>
And below in root level pom (packaging type pom)
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>${version.plugin.surefire}</version>
<inherited>false</inherited>
<configuration>
<aggregate>true</aggregate>
<linkXRef>true</linkXRef>
</configuration>
</plugin>
</plugins>
</reporting>
Could some one please help where I am going wrong ?

Try with mvn surefire-report:report -Daggregate=true

Related

How to override configLocation of a Maven Checkstyle Plugin

I want to override a configLocation that is originally declared in a configuration of a maven-checkstyle-plugin in the parent pom.xml.
But when I'm executing mvn clean package in the child project it's ignoring <configLocation>child-stylecheck.xml</configLocation> and uses parent-stylecheck.xml instead. The child-stylecheck.xml is located in the root of the project next to the pom.xml.
What could be wrong in my configurations?
Plugin configuration in the parent pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-version}</version>
<configuration>
<configLocation>parent-stylecheck.xml</configLocation>
<outputFileFormat>xml</outputFileFormat>
<failOnViolation>true</failOnViolation>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Plugin configuration in the child pom.xml
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle-version}</version>
<configuration>
<configLocation>child-stylecheck.xml</configLocation>
<suppressionsFile>parent-stylecheck.xml</suppressionsFile>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

maven-jar-plugin not finding my main class

I've got a Java/Selenium/TestNG/Maven project. I can successfully create the myproj-0.0.1-SNAPSHOT.jar file. When I try to run it I'm getting an error:
$ java -jar myproj-0.0.1-SNAPSHOT.jar
Error: Could not find or load main class utilities.MavenTestInvoker
My main goal is to be able to run this SNAPSHOT.jar file to run my test cases on a remote machine.
I'm using a build plugin in my pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>utilities.MavenTestInvoker</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
When I build the project I'm using the maven command: "mvn clean package shade:shade"
That creates my uber jar.
Here are the dependencies:
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
</dependency>
plus some others
</dependencies>
What am I doing incorrectly?
The correct usage of including plugin dependencies is as follows, you can merge the plugin dependencies at a single place -
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<!--Notice I have removed the configs here. Not required to generate the jar-->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Further you can edit the respective plugin configs within the same declaration.
Also for using maven-shade-plugin and maven-jar-plugin, you might want to look into the samples here and here respectively.
Remember that your project must have the right folder structure, for example your code must be in src/main/java

Maven - maven-plugin-api, maven-project and other jars in WEB-INF/lib

I have a maven build that is copying a bunch of jars that it should not be into WEB-INF/lib for my war project.
The jars do not show up in the output of mvn dependency:tree but mvn package puts these (among other) jars into the WEB-INF/lib directory of the generated war file:
maven-artifact, maven-artifcat-manager, maven-profile, maven-project, maven-settings...
Where are these coming from? What (other than dependency:tree) might show me what is causing these jars to be included? I have done a mvn clean and rebuild and same thing.
It seems that when I add this plugin I get the extra jars added:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.2.0</version>
<executions>
<execution>
<id>xmlbeans-generate-compile</id>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
<goal>xmlbeans-test</goal>
</goals>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<sourceGenerationDirectory>src/xmlbean/java</sourceGenerationDirectory>
<classGenerationDirectory>target/xmlbean/build</classGenerationDirectory>
<schemaDirectory>src/main/components</schemaDirectory>
</configuration>
</plugin>
</plugins>
The rest of the POM is just dependency stuff and this:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/tests</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.15</version>
</dependency>
</dependencies>
</plugin>

Eclipse deletes files under WEB-INF on every run

I'm trying to setup Maven with my GWT project but every time that I start debugging, it deletes web.xml and other files that are required to start.
Code fragment related to build from my pom.xml :
<build>
<outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<webXml>${webappDirectory}/WEB-INF/web.xml</webXml>
<source>${target.jdk}</source>
<target>${target.jdk}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archiveClasses>true</archiveClasses>
</configuration>
</plugin>
</plugins>
</build>

maven 3 + pmd fails when code has annotations and generics

When I run mvn pmd:pmd I get an warning / error from PMD saying that the code cannot use generics, annotations or Enums with java 1.4 or 1.5. This is supposed to be a error when the targetJdk property is not set (which I did set).
Here is an example of the error I get
[WARNING] Error while parsing /Users/augusto/Downloads/PMD-Clover2-Cobertura-Maven2-Test/PMDTest/src/main/java/org/xh/studies/quality/App.java: Can't use generics unless running in JDK 1.5 mode!
and here's a snippet of the pom I'm using (there's a link to the whole app below)
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
<configuration>
<targetJdk>1.6</targetJdk>
</configuration>
</plugin>
</plugins>
</reporting>
I'm using Maven 3.0.2 on mac, with the latest java patch 1.6.0_24.
Click here to download the full project (8kb)
EDIT (26/03/2014)
Since version 3.3 of the maven site plugin, maven can also use the old style configuration (and in fact the maven 2 style is now recommended). Links: docs, jira.
Original answer
Pain, the answer is that the site generation changed completely from maven 2 to maven 3. There is an explanation on this blog. Note that mvn pmd:pmd doesn't work anyway with the new reporting configuration, but it works as part of the site generation.
And here's an example of a pom that works.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.0-beta-2</version>
<configuration>
<reportPlugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<dependencyDetailsEnabled>false</dependencyDetailsEnabled>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>javancss-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jdepend-maven-plugin</artifactId>
<version>2.0-beta-2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
<configuration>
<linkXRef>false</linkXRef>
<sourceEncoding>utf-8</sourceEncoding>
<minimumTokens>100</minimumTokens>
<targetJdk>${java-version}</targetJdk>
<verbose>true</verbose>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.6</version>
</plugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>

Categories