How to generate two separate Maven CheckStyle HTML reports? - maven

I'd like to to generate two separate Maven HTML CheckStyle reports with different configurations:
the first one checks the main classes (src/main/java/**) with configuration #1 (<configLocation>)
the second one checks the test classes (src/test/java/) with configuration #2 (<configLocation>) which is somewhat relaxed regarding of configuration #1
I played a lot with multiple executions, configurations, and reportSets, etc. but I've never been able to make it work. The generated report only take into account the last execution of the plugin. I'm now wondering if it's even possible...
Edited:
Added HTML report.

You need to specify outputFile property in your config to set different file for report. And create 2 executions for main code and test code with different output files.
For example, config below will generate result report in file your_file.xml in base directory of your project.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.plugin.version}</version>
<configuration>
<outputFile>${project.basedir}/your_file.xml</outputFile>
</configuration>
</plugin>
Full description of property is here

Related

Aggregated Karate test Report and Continuous Testing

After running a test case with Karate, some html reports are published with surefire plugin. In particular, I've found that there is an html report for each feature file. This is inconvenient when tests are run from an automated pipeline, like in my case, where I use htmlpublish Jenkins plugin to get a public link to access reports and spread them across slack channels or emails.
I've tried to add this snippet in my pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<aggregate>true</aggregate>
<!--also set this to link to generated source reports-->
<linkXRef>true</linkXRef>
</configuration>
</plugin>
But it had not the desired effect.
I'm trying to achieve a single index.html into the target/surefire-reports directory so i can publish and browse all test reports
Any suggestion?
Thanks
Are you using the parallel runner ? If not, please read up about it: https://github.com/intuit/karate#parallel-execution
Since we emit the cucumber-compatible JSON report in addition to the industry-standard JUnit XML format, you have the choice of any reporting solution that fits your needs. I think the maven-cucumber-reporting library should work for you - but you can decide: https://github.com/intuit/karate/tree/master/karate-demo#example-report
EDIT: For any other advanced needs, please consider writing your own report: https://stackoverflow.com/a/66773839/143475

How can you chain/stitch Maven plugins?

I want to chain two Maven plugins which should execute in sequence. The output from the first plugin should be used as input for the second plugin. Let me explain:
I want to write a plugin which generates resources and sources, such as configuration files, Java classes, ... Let's call this plugin generator-plugin.
This plugin needs input information to generate all this. This information can be retrieved from file system or from a SQL database. Possibly, in the future one might introduce several other input sources. My idea is to write two plugins, one for getting all information from the file system and another from a SQL database.
This gives:
information-plugin-file ---\
|--- generator-plugin
information-plugin-sql ---/
How can this be done with Maven? Can you chain plugins? I am familiar with writing basic Mojo's, but I have no idea how to approach this, hence this question.
One possibility is to output to a standardized file in information-plugin-file/information-plugin-sql and let the subsequent generator-plugin plugin read from the same file (the Unix way of working, everything is a file).
But I am looking for more direct, Maven specific approaches of doing this. Are there such approaches?
With regards to execution order, all plugins will run in the generate-sources phases and will be defined in correct order in the <plugins> section. So that is already covered I think.
AFAIK, plugins in maven are designed to be totally independent, so the following methods of sharing the information can be used:
Sharing via maven properties:
Its possible to set a property in the first plugin, and probably it will be accessible from within the second plugin
import org.apache.maven.project.MavenProject;
// now inject it into your mojo of the first plugin
#Parameter(defaultValue = "${project}")
private MavenProject project;
// Inside the "execute" method:
project.getProperties().setProperty("mySampleProperty", <SOME_VALUE_GOES_HERE>);
Sharing via Files
The first plugin can generate some output file in the 'target' folder
And the second plugin can read this file
Write a "wrapping" plugin that executes other plugins (like both first and second plugin). After all mojos are just java code that can be called from the aggregator plugin
You can find Here more information about this method
I believe the only way you can have something ordered in Maven is through lifecycles. You could have your first plugin (for the input information) run in the generate-sources phase, and the second in process-sources phase.

Can surefire and failsafe plugin deliberately randomize execution order of test classes?

It appears that surefire and failsafe plugins execute test classes in order while tests defined within a class execute in undetermined order.
To discover tests which rely on order (what we consider bad tests) we want to force the order to be different for each run. Ideally, we'd have a mechanism to disable randomization or a seed number that would repeat the order (must like the old palm OS emulator had a seed number that drove a sequence of random tests).
Let me know if you know a way to do this? If not, I guess I can work one into a local fork and then submit it.
Thanks
Peter
Some of the other answers link to the surefire maven documentation page, but like most maven documentation it provides no examples of how to actually specify the settings in the maven XML morass. Here is how to do it with the surefire plugin:
<properties>
<surefire.plugin.version>2.16</surefire.plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<runOrder>random</runOrder>
</configuration>
</plugin>
</plugins>
</build>
Specify the runOrder of Surefire to "random" http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#runOrder
I think this is more the responsibility of your unit test framework, not the Surefire/Failsafe plugins, which are just responsible for bootstrapping the test framework.
There is already a Stackoverflow question about how to make Junit tests run in random order (the answer is to use a custom ClassRunner):
How can I make my JUnit tests run in random order?
This library supplies an implementation if you don't want to write your own: http://randomjunit.sourceforge.net/
First it seemed to me that you are mixing things. Maven-Surefire-PLugin is responsible to run unit tests where it is the case to be independant of the order of execution.
Maven-Failsafe-plugin is responsible for exectution of integration tests which is different, cause integration tests could be dependant on the order which os no problem. Apart from that maven-surefire-plugin has some possibilities to influcence of the order of execution order:
http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#runOrder
This will be of course influenced by the testing framework which you use. In JUnit you can influence the order only in limited way. In TestNG it is a complete different story, cause TestNG has the ability to define dependencies etc.
Maven-Failsafe-Plugin has the same capabilities to influence the order of executions.
http://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html#runOrder

How to turn off auto-generation of the GWT Asynchronous RPC interface in Maven

I'm working with a Java RPC service to communicate between the server and client side in my GWT application. I don't want to remove the asynchronous interface from my version control, because it's required in order for the project to compile and run.
However, the Async interface gets generated automatically (along with the Messages class) in the target/generated-sources folder by a Maven plugin, and I get a duplicate class error when the application tries to run.
Does anybody know how to disable the auto-generation of the Asynchronous RPC interface?
I found the answer by following this question:
How to configure IntelliJ IDEA and/or Maven to automatically add directories with Java source code generated using jaxb2-maven-plugin?
And then looking at the Maven GWT plugin at Mojo's website:
http://mojo.codehaus.org/gwt-maven-plugin/user-guide/async.html
... so it wasn't IDEA that was generating the code, but rather it was the GWT Maven plugin. I disabled the auto-generation of the Async RPC and i18n Messages interfaces by commenting out the following two lines in my pom:
<goal>i18n</goal>
<goal>generateAsync</goal>
so that the plugin definition in pom.xml now looks like:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<!--<goal>i18n</goal>-->
<!--<goal>generateAsync</goal>-->
</goals>
. . .
And the problem is solved.
Actually commenting your POM is not the best way to do it.
I don't know about IDEA but with Eclipse "run configurations" you can specify the goals you want to execute. I guess IDEA must have something similar (see link).
For instance I would have two distinct runners. One with the goals
gwt:generateAsync gwt:i18n gwt:css
and one with no specific goals, which will execute a full build.
clean install
In your case you would want to have
gwt:compile gwt:test
If you NEVER want to execute the gwt:generateAsync goal though, removing it might be considered as a good option.

GWT No source code is available for type [userClassName]

OK, this error started occuring this morning. I have a Maven project called "snmp-jobs" which was previously used only to convey SNMP communication. Due to changes done lately this project now contains DTO classes as well. Also, there are now two main sub-packages: shared and server where first one contains those DTOs and second server-side code. This projects also has .gwt.xml file which specifies:
<source path="shared"/>
Another project, called "mib" references "snmp-jobs" and uses those DTO classes in client code. To be more exact, problematic class is called MibRow.
When I compile the GWT project it reports the error:
No source code is available for type "rs.jp.jobs.shared.MibRow"; did you forget to inherit a required module?
I understand that this is really common error. As far as I understand, GWT cannot find sources for MibRow class and cannot proceed with GWT compilation. Is this true?
I have tried all by-the-book suggestions but none of them have solved the issue so far. Anyone can give me a hint on what to try next?
Thanks a lot!
UPDATE:
I have run compilation from console with -Dgwt.logLevel=DEBUG and there are two lines that stick out:
Loading inherited module 'rs.jp.jobs.Jobs'
[INFO] Module location: USER_DIR/.m2/repository/rs/jp/jobs/snmp-jobs/1.0.4-SNAPSHOT/snmp-jobs-1.0.4-SNAPSHOT.jar!/rs/jp/jobs/Jobs.gwt.xml
and
Errors in 'rs/jp/mib/client/commands/mib/report/DataResponse.java'
[INFO] Line 10: No source code is available for type rs.jp.jobs.shared.MibRow; did you forget to inherit a required module?
Apparently, GWT managed to find the Jobs module but is unaware of shared package :-/
OK, I have managed to resolve this issue. I was missing the following XML block from pom.xml within snmp-jobs project:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Hope this will be helpful to someone :)

Resources