Publish report for maven compiler plugin xlint - maven

I would like to capture warnings/errors generated by maven-compiler-plugin (when running compile goal) and output them to a file (be it xml or json).By default, maven-compiler-plugin doesn't provide the option to configure a reporter. So, curious to know how this can be done. Here's my plugin config -
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.0</version>
<configuration>
<compilerArgs>
<arg>-verbose</arg>
<arg>-Xlint:all,-options,-path</arg>
</compilerArgs>
<showWarnings>true</showWarnings>
</configuration>
</plugin>

Related

maven-compiler-plugin report generation

I would like to capture warnings/errors generated by maven-compiler-plugin (when running compile goal) and output them to a file (be it xml or json). I would then like to view the file on CI console. By default, maven-compiler-plugin doesn't provide the option to configure a reporter. So, curious to know how this can be done. Here's my plugin config -
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-Xlint:all</compilerArgument>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
</plugin>

Dagger2 on an AJC maven-compiled project

Due to inter-type declarations the project I'm currently working on has it's pom.xml set to use ajc disabling javac.
// disable javac
<build>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
We were planing to use Dagger2 but that would require to put dagger-compiler as an <annotationProcessorPaths> to be used by the disabled javac.
As aspectj-maven-plugin does not support the required <annotationProcessorPaths> I'm a bit at lost here. Any simple solution I'm not seeing or should I simply go with Guice?

Maven Report Configuration vs Build Configuration

It is interesting what is the differences between
report->configuration element and build->configuration element in POM.
It is written in POM references:
Subtle difference is that a plugin configuration under the reporting
element works as build plugin configuration, although the opposite is
not true (a build plugin configuration does not affect a reporting
plugin).
See http://maven.apache.org/pom.html#Reporting
Could you give particular example of the differences in behaviour?
This statement means the following:
If we have report generation plugin configuration like
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.8</version>
<configuration>
<linkOnly>true</linkOnly>
</configuration>
</plugin>
</plugins>
</build>
then linkOnly configuration property won't be used when invoking site generation command
mvn site
Instead, we should use the same configuration under reporting element:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.8</version>
<configuration>
<linkOnly>true</linkOnly>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>license</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
Here we generate only license report with configuration parameter linkOnly=true.
I.e. build configuration is not used.
Note:
If we explicitly invoke report generation goal "license"
mvn project-info-report:license
then it will use configuration under build element.
I.e. we have opposite behaviour here.

maven goal doesn't execute properly if plugins are defined under pluginManagement

I have maven-jaxb2-plugin. I generate jaxb objects and refer it in other classes of project.I've put jaxb plugin and compiler plugin under pluginManagement tag. Maven is executing compile phase first than generate phase where as if i remove pluginManagement tag, it works fine, first generate phase gets executed and all jaxb object gets generated and then compile phase gets executed. Due to pluginManagement tag, my project doesn't compile. Is pluginManagement tag used only for defining all the plugins in parent pom so that child pom can refer to these plugins ? My project is not a multi-module project.
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/schema</schemaDirectory>
<generatePackage>com.common.dto</generatePackage>
<schemaIncludes>
<include>*.xsd</include>
</schemaIncludes>
<removeOldOutput>false</removeOldOutput>
<strict>false</strict>
<verbose>true</verbose>
<forceRegenerate>true</forceRegenerate>
<extension>true</extension>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Yes, <pluginManagement> is used to create ready-to-use configurations, but does not automatically activate your plugins - you still need to include them.
So in effect you are right, <pluginManagement>, just like <dependencyManagement> are very useful in the parent pom to centralize plugin configurations and dependency management.
Effectively, 'declaring' your plugins in the right module benefits from a much more compact syntax:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
</plugin>
</plugins>

Disable sure-fire and execute fail-safe report to run my test cases in a Maven project

In my parent POM I have configured for sure fire report. But in some modules, I need to skip the sure fire report generation and instead I want to run fail-safe plugin to generate the test report.
I have tried like
<properties>
<skipTests>true</skipTests>
<skipFailsafeTests>false</skipFailsafeTests>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.5</version>
<configuration>
<skipTests>${skipFailsafeTests}</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipExec>${skipTests}</skipExec>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
But still it seems sure-fire report is running. Is there any way to overcome it?

Resources