Maven goal to generate test report using damage control - maven

I'm using Spock to test a Java application. I would like to generate test reports, in html, using damage-control
What maven goal shoud be executed to generate the reports?

It generated the reports running:
mvn com.github.damage-control.report:damage-control-maven-plugin:report

You should use goal provided by plugin.
Maven provides only phase's, not goals
So you should use phase test and goal report.
<execution>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
report goal is declared in this file DamageControlMojo.
/**
* #goal report
*/

Related

Trigger a Mojo programmatically from another Mojo

Can I make a Mojo that runs during integration-test phase trigger another Mojo that runs during verify phase?
This question is a follow up on my previous question. I extended the frontend-maven-plugin with a parameter that delays build failure from integration tests until the verify phase to allow the post-integration-test phase to execute properly. This is often needed to clean up the environment (close DB, server, ...). Pull request commit available here.
The solution is rather hacky because it requires the user to add a verify execution phase, even if it doesn't do anything. Instead, I would like an execution on the integration-test phase to automatically execute a Mojo during the verify phase (without the user explicitly adding this to the Maven configuration). So the following:
<execution>
<id>npm run integration tests</id>
<goals>
<goal>npm</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<arguments>run e2e</arguments>
<integrationTestFailureAfterPostIntegration>true</integrationTestFailureAfterPostIntegration>
</configuration>
</execution>
should trigger e2e tests to run during integration-test phase, but also needs to execute another Mojo during verify phase.
Is this possible and how would you do it?
UPDATE: I managed to add another pluginExecution at runtime to the plugin like so:
for (Plugin plugin : project.getBuildPlugins()) {
if("com.github.eirslett".equals(plugin.getGroupId()) && "frontend-maven-plugin".equals(plugin.getArtifactId())){
PluginExecution verifyExecution = new PluginExecution();
verifyExecution.addGoal("verify");
verifyExecution.setId("verify integration tests");
verifyExecution.setPhase("verify");
plugin.addExecution(verifyExecution);
}
}
but this does not seem to affect the runtime executions. The goal is a custom verify Mojo that performs the validation during the verify phase

maven surefire reports in default lifecyle

How can i generate surefire reports in the maven's default lifecycle. We have jobs setup in teamcity with goals as
mvn clean install -Pprod
This job runs all the junits, i want to create HTML report of all the tests running in the project. I came across the sure-fire-reports plugin but it generates the report only in site phase it does not generates the report during the default clean install phase.
Can one please help how can i generate report default lifecycle
I tried including the surefire-reports plugin, in test phase as below but doesnot not works
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>report-only</goal>
</goals>
</execution>
</executions>
</plugin>
If you need the very report generated by maven-surefire-report-plugin, I see no other way than execute mvn site, because a report is executed only within the site phase of the build lifecycle.
Instead, if you just need an HTML-readable report, I'd suggest you this walk-around:
Take advantage of the XML files generated by the maven-surefire-plugin in the target/surefire-reports directory.
Code your own transformation sheet (XSL) to transform them to the desired HTML format.
In the pom, set a transformation in the next phase (for example, prepare-package) through the xml-maven-plugin.
If you put the XSL in the parent project and set this transformation in the parent pom, all the submodule projects should inherit it and produce the HTML reports during the corresponding build.
And last: How to browse the child HTML reports from the parent project? Hum... I'd say to code an Ant script to browse all the submodules and list the HTML files and produce an HTML index with them. This script should be executed only from the parent project.

What does "echo" mean when it comes to using Maven?

I'm currently learning how to use Maven and have encountered a term called "echo". I was just wondering what it actually means?
There are few important concepts related to Maven Lifecycles, which
are worth to mention:
1) When a phase is called via Maven command, for example mvn compile,
only phases up to and including that phase will execute.
2) Different maven goals will be bound to different phases of Maven
lifecycle depending upon the type of packaging (JAR / WAR / EAR).
In the following example, we will attach maven-antrun-plugin:run goal
to few of the phases of Build lifecycle. This will allow us to echo
text messages displaying the phases of the lifecycle.
echo is an ant task which allow to print messages to console (system.out)
This makes sense when using maven-antrun-plugin which allow to execute ant tasks in a maven build.
It can be used to print some maven properties during the build as there is no built-in way to output value to console in maven.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>${maven.antrun.plugin.version}</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Configuration properties :</echo>
<echo>service.endpoint=${service.endpoint}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
It means to use echo tag in ant script executed by maven-antrun-plugin:run. Nothing directly related to maven itself.

Multi module project analysis with SonarQube

SonarQube Server 5.1.2, Sonar-Runner 2.4
As provide in Multi-moduleProject i have created a project structure as
Accounts
|
->invoice
|
->src
->receipt
|
->src
->sonar.properties
File:sonar.properties
sonar.projectKey=org.mycompany.acc
sonar.projectName=Account
sonar.projectVersion=1.0
sonar.sources=src
sonar.modules=invoice,receipt
invoice.sonar.projectName=Invoice
receipt.sonar.projectName=Receipt
When execute with above configuration in sonar-runner i encountered with error "src" folder is missing in "Account" directory, hope this configuration is same as the conf available in that link. As per the understanding if the configuration is fine then the Invoice and Receipt will be listed as sub project under Account Project, so what are the changes are required in above configuration to achieve multi module / project under one project.
ERROR
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: The folder 'src' does not exist for 'org.mycompany.acc' (base
directory = C:\Users\xyz\Accounts\.)
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with t
he -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
try this:
sonar.projectKey=org.mycompany.acc
sonar.projectName=Account
sonar.projectVersion=1.0
sonar.sources=src # try to remove this by the way if you don't have suchdirectory under root folder of project
sonar.modules=invoice,receipt
invoice.sonar.projectName=Invoice
invoice.sonar.sources=invoice/src
receipt.sonar.projectName=Receipt
receipt.sonar.sources=receipt/src
You can try this option, If you want scan multiple projects at same time OR in same build then try this option.
sonar.sources=invoice,receipt
sonar.modules property was deprecated long time ago. Use sonar.sources parameter to perform a scan.
In short, you have to specify in sonar:sonar goal parameters where the sources and reportPaths are located for the required modules and declare jacoco configuration for each module respectively. As a result, it will look something like this:
Jacoco plugin declaration in each module:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Sonar goal execution:
mvn clean verify sonar:sonar /
-Dsonar.projectKey=... /
-Dsonar.host.url=... /
-Dsonar.login=... /
-Dsonar.branch.name=... /
-Dsonar.sources=../module1/src/main,../module2/src/main /
-Dsonar.jacoco.reportPath=module1/target/jacoco.exec,module2/target/jacoco.exec
Important! It's required to specify .. before module name in -Dsonar.sources parameter because jacoco plugin in each module can only read content by relative path from it's location.

Stop Tests on first Failure with Maven/JUnit/Spring

I'd like Maven to stop trying to run my JUnit Spring tests when it encounters the first error. Is this possible?
My test classes look like the following, and I run them just as a standard Maven target.
#ContextConfiguration(locations = {"classpath:/spring-config/store-persistence.xml","classpath:/spring-config/store-security.xml","classpath:/spring-config/store-service.xml", "classpath:/spring-config/store-servlet.xml" })
#RunWith(SpringJUnit4ClassRunner.class)
#Transactional
public class SkuLicenceServiceIntegrationTest
{
...
If there's an error in the Spring config, then each test will try to restart the Spring context, which takes 20 seconds a go. This means we don't find out for ages that any tests have failed, as it'll try to run the whole lot before concluding that the build was a failure!
Answering ten years later, since I needed exactly the same.
The failsafe plugin can be configure to "skip tests after failure", using the skipAfterFailureCount parameter.
Official documentation:
https://maven.apache.org/surefire/maven-failsafe-plugin/examples/skip-after-failure.html
This is more a remark, than an answer, but still, maybe you'll find it useful.
I'd recommend separating your integration tests into a separate phase, and running them with Failsafe, rather than Surefire. This way you can decide whether you need to run only fast unit tests, or the complete set with long-running integration tests:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<!-- Uncomment/comment this in order to fail the build if any integration test fail -->
<execution>
<id>verify</id>
<goals><goal>verify</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
A workaround for your problem might be singling out a test into a separate execution and run it first; this way the execution would fail and subsequent surefire/failsafe executions will not be launched. See how to configure the plugin to do it.

Resources