I'm running Jacoco as an agent to surefire
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<argLine>${jacoco.agent.argLine}</argLine>
</configuration>
</plugin>
I'm configuring Jacoco with a large list of exclusions (constants and my deprecated classes) for my build-breaker.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<excludes>
<exclude>*/*Test</exclude>
<exclude>*/*Constants*</exclude>
<exclude>${jacoco.exclusions.list}</exclude>
</excludes>
</configuration>
What I'm getting is that when I go to run the tests I get the error:
T E S T S
-------------------------------------------------------
The command line is too long.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
Is there another way to pass the exclusions list to Jacoco than on the agent parameter arglist on the command line? (Looking at the code it doesn't look like it)
My question is: How to pass the list of exclusions to the Jacoco agent running in surefire other than on the command line?
As of today JaCoCo Java Agent doesn't allow reading of options from files.
However you can specify agent via environment variable JAVA_TOOL_OPTIONS, which supposed to have bigger size limit than command line.
Also JaCoCo in offline mode (without agent) allows to provide configuration via file jacoco-agent.properties.
Related
I have a scala project configured with maven surefire plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
When I run all the tests and generates the test report, I found the following information on the index page:
Surefire Report
Summary
[Summary] [Package List] [Test Cases]
Tests Errors Failures Skipped Success Rate Time
0 0 0 0 0% 0
It appears that all scalatest result under test-results/scalatest are ignored! How could this happen? This will never happen to gradle test report.
I just found out that scalatest was not designed to work with either maven-surefire-plugin or maven-surefire-report-plugin, it has to generate its own test report in html format:
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<reportsDirectory>${project.build.directory}/test-results/scalatest</reportsDirectory>
<junitxml>.</junitxml>
<htmlreporters>${project.build.directory}/site/scalatest</htmlreporters>
...
case closed.
I have a multi module project with a plugin and fragment to test this plugin.
The build is done through maven/tycho. Maven v.3.8.4 and Tycho v2.6.0.
In the fragment I have 3 Unit and 1 Integration test, in the test folder:
test
├── CoreTestConstants.java
├── CoreUtils2Test.java
├── CoreUtils3Test.java
├── CoreUtilsIT.java
└── CoreUtilsTest.java
This is the pom of the fragment plugin:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>4.0.0</modelVersion>
<artifactId>com.tycho.rcp.core.test</artifactId>
<version>0.2.4-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<parent>
<groupId>com.tycho</groupId>
<artifactId>com.tycho.mps</artifactId>
<version>0.3.4-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<executions>
<execution>
<id>it-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
<configuration>
<testSourceDirectory>src</testSourceDirectory>
<testClassesDirectory>target/classes</testClassesDirectory>
<!-- workspace directory -->
<osgiDataDirectory>${mas.test.workspace}</osgiDataDirectory>
<!-- system properties -->
<systemProperties>
<mas.test.archive_location>${mas.test.archive_location}</mas.test.archive_location>
</systemProperties>
<!-- add slf4j implementation dependency from Orbit -->
<dependencies>
<dependency>
<groupId>org.eclipse.orbit.bundles</groupId>
<artifactId>ch.qos.logback.slf4j</artifactId>
<version>1.1.2</version>
<type>eclipse-plugin</type>
</dependency>
</dependencies>
</configuration>
</plugin>
</plugins>
</build>
</project>
The tycho-surefire-plugin is enabled in pluginManagement of the parent project:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho.version}</version>
</plugin>
The 3 Unit test are executed correctly, but the IT test is never run!
This is the relevant part of the output, when I run mvn clean verify inside the fragment project:
[INFO] --- tycho-surefire-plugin:2.6.0:test (default-test) # com.marchesini.mas.rcp.core.test ---
[INFO] Executing Test Runtime with timeout 0, logs (if any) will be placed at: /home/gionata/runtime-EclipseApplication/.metadata/.log
[INFO] Command line:
[/usr/lib/jvm/java-11-openjdk-11.0.9.11-0.fc31.x86_64/bin/java, -Dosgi.noShutdown=false, -Dosgi.os=linux, -Dosgi.ws=gtk, -Dosgi.arch=x86_64, -Dosgi.clean=true, -Dmas.test.archive_location=/home/gionata/ARCHIVIO.BLK, -jar, /home/gionata/.m2/repository/p2/osgi/bundle/org.eclipse.equinox.launcher/1.5.100.v20180827-1352/org.eclipse.equinox.launcher-1.5.100.v20180827-1352.jar, -data, /home/gionata/runtime-EclipseApplication, -install, /home/gionata/Workspace_Eclipse_Maven/MAS/MPS/com.marchesini.mas.rcp.core.test/target/work, -configuration, /home/gionata/Workspace_Eclipse_Maven/MAS/MPS/com.marchesini.mas.rcp.core.test/target/work/configuration, -application, org.eclipse.tycho.surefire.osgibooter.headlesstest, -testproperties, /home/gionata/Workspace_Eclipse_Maven/MAS/MPS/com.marchesini.mas.rcp.core.test/target/surefire.properties]
Running com.marchesini.mas.rcp.core.test.CoreUtils2Test
Logger launcher start...4
2022-02-05 18:36:11,221 DEBUG [main]: CHECKSUM 2 = 340351cde832c00505c88f3fe1a962d4
2022-02-05 18:36:11,442 DEBUG [main]: Workspace = /home/gionata/runtime-EclipseApplication
2022-02-05 18:36:11,442 DEBUG [main]: Archive location = /home/gionata/ARCHIVIO.BLK
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.569 s - in com.marchesini.mas.rcp.core.test.CoreUtils2Test
testCoreUtils2(com.marchesini.mas.rcp.core.test.CoreUtils2Test) Time elapsed: 0.226 s
Running com.marchesini.mas.rcp.core.test.CoreUtilsTest
#################################################################################
REPORT
CHECKSUM = 340351cde832c00505c88f3fe1a962d4
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 s - in com.marchesini.mas.rcp.core.test.CoreUtilsTest
testCoreUtils(com.marchesini.mas.rcp.core.test.CoreUtilsTest) Time elapsed: 0.002 s
Running com.marchesini.mas.rcp.core.test.CoreUtils3Test
Logger launcher start...4
2022-02-05 18:36:11,537 DEBUG [main]: CHECKSUM 3 = 340351cde832c00505c88f3fe1a962d4
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.024 s - in com.marchesini.mas.rcp.core.test.CoreUtils3Test
testCoreUtils3(com.marchesini.mas.rcp.core.test.CoreUtils3Test) Time elapsed: 0.001 s
Results:
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
[INFO] All tests passed!
[INFO]
[INFO] --- tycho-surefire-plugin:2.6.0:integration-test (it-test) # com.marchesini.mas.rcp.core.test ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
The execution it-test simply doesn't run anything! I have been wasting hours on this....
Thankyou for any help.
First of all, you shouldn't add any specific configuration if you follow the default conventions. Moreover, parameters like <testSourceDirectory>src</testSourceDirectory> are not read by the tycho surefire plugin. Moreover, there's no need to create products or features for what you need. The reason why it's not working it's because of a bug:
https://github.com/eclipse/tycho/issues/643
On a side note, I've updated the RELEASE notes
https://github.com/eclipse/tycho/pull/641
trying to document better the rationale behind the new goal (but, again, it does not work due to a bug)
My requirement is that I have to generate the springboot server code from a swagger definition. I have generated the code with the help of below-mentioned command (by using swagger-codegen-cli-2.3.1.jar).
java -jar swagger-codegen-cli-2.3.1.jar generate ^
-i nycemoves.yml ^
--api-package com.nyce.moves.api ^
--model-package com.nyce.moves.model ^
--invoker-package com.nyce.moves.invoker ^
--group-id com.nyce.moves ^
--artifact-id nyce-moves ^
--artifact-version 0.0.1-SNAPSHOT ^
-l spring ^
--library spring-boot ^
-o nyce-moves
Now, we have updated the swagger definition and want to re-generate the resulting models and api-invokers, for this we would like to use a maven plugin.
After looking through various answers on the internet, we came across the following build plugins which we have added in our pom.xml.
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/resources/nycemoves.yml</inputSpec>
<language>spring</language>
<basePackage>${default.package}</basePackage>
<modelPackage>${default.package}.model</modelPackage>
<apiPackage>${default.package}.api</apiPackage>
<invokerPackage>${default.package}.invoker</invokerPackage>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<library>spring-boot</library>
<serializableModel>true</serializableModel>
<sourceFolder>src/main/java</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Now, when we do mvn clean package, we want it to update / override all the models, api and invokers. But, this is not working. We are seeing the below mentioned exception.
[INFO] 16 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.516 s
[INFO] Finished at: 2019-03-06T15:05:58+05:30
[INFO] Final Memory: 34M/448M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project nyce-moves: Compilation failure: Compilation failure:
[ERROR] /nyce-moves/src/main/java/com/nyce/moves/api/CommentsApi.java:[29,8] duplicate class: com.nyce.moves.api.CommentsApi
[ERROR] /nyce-moves/target/generated-sources/swagger/src/main/java/com/nyce/moves/model/PostRequest.java:[19,8] duplicate class: com.nyce.moves.model.PostRequest
...
So, we actually need the plugin to do the following things, but we are not able to figure it out.
a) When we run mvn clean package it should regenerate all the source-code for the server stub in source folder as well as target folder.
b) In case of the class already exists, it should override them. We would like to handle the override later with the help of .swagger-codegen-ignore.
I know there are lots of discussion threads on this on stackoverflow, but I could not find any solution which can help me here. Please help me on this or direct me to the relevant thread.
I had the same problem and I needed to define also the output directory. Here is a snippet:
<configuration>
<language>spring</language>
<library>spring-cloud</library>
<configOptions>
<sourceFolder>swagger</sourceFolder>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8</dateLibrary>
</configOptions>
<output>${project.build.directory}/generated-sources</output>
</configuration>
SonarQube is reporting the following for my project.
Unit Tests Coverage 0.0%; Line Coverage 0.0%; Condition Coverage 0.0%
It is not able to find the reports which was created immediately before the Sonar scan. I am using Jenkins to launch the SonarQube scan. In fact in the console output I can see the unit tests being executed and the reports saved in the surefire directory.
Below are the relevant logs from the console output.
[INFO] --- maven-surefire-plugin:2.12:test (default-test) # earn-promotional-domain ---
[INFO] Surefire report directory: /var/jenkins/workspace/earn/surefire-reports
[INFO] [13:50:20.807] Sensor SurefireSensor
[INFO] [13:50:20.807] parsing /var/jenkins/workspace/earn/surefire-reports
[ERROR] [13:50:20.808] Reports path not found or is not a directory: /var/jenkins/workspace/earn/surefire-reports
[INFO] [13:50:20.808] Sensor SurefireSensor (done) | time=1ms
[INFO] [13:50:20.808] Sensor CoberturaSensor
[INFO] [13:50:20.808] parsing /var/jenkins/workspace/earn/site/cobertura/coverage.xml
I am using SonarQube 5.1.2. Please let me know if any other information is needed that will help to figure out the problem.
You are better off with Jacoco than cobertura. Cobertura has lot of open bugs yet to be addressed.
Also Jacoco provides a aggregator plugin which will aggregate the coverage from all child modules and display a comprehensive coverage.
Jacoco also doesnt require any additional plugin for SonarQube.
Here's a good example of implementing Jacoco:
http://www.petrikainulainen.net/programming/maven/creating-code-coverage-reports-for-unit-and-integration-tests-with-the-jacoco-maven-plugin/
If you prefer to stick with Cobertura rather than moving to Jacoco, you can try this alternative to cobertura maven plugin:
https://github.com/QualInsight/qualinsight-mojo-cobertura
Here are some advantages this mojo provides:
it runs tests once (instead of twice with cobertura-maven-plugin)
it allows you to split coverage (UT / IT / Overall)
you get rid of the "obsolete" Cobertura plugin for SonarQube
The documentation on the project's page explains how to add converted reports to SonarQube.
As #Jeel said, you can use an alternative plugin. But if you necessarily must use the cobertura plugin, you can modify it a little bit.
If I understand correctly, the cobertura:check goal forks a current lifecycle, merges a plugin specific configuration (cobertura-maven-plugin-X.X.jar\META-INF\maven\lifecycle.xml) and executes a forked lifecycle to the test phase. After that "check" mojo is executed.
To make cobertura not to fork a lifecycle you can comment <executePhase> tag in a plugin descriptor (cobertura-maven-plugin-X.X.jar\META-INF\maven\plugin.xml) for the check goal.
Additionaly, you have to copy the configuration from lifecycle.xml to your build configuration. For version 2.7 there is only surefire configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<classesDirectory>${project.build.directory}/generated-classes/cobertura</classesDirectory>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
</plugin>
(possibly extending a default lifecycle using components.xml would also work).
In the last step you have to add an execution for the "instrument" goal in the "process-class" phase because it doesn't have a default phase in a plugin descriptor.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.version}</version>
<executions>
<execution>
<id>instrument-classes</id>
<phase>process-classes</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>check-coverage</id>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
I'm using this in my pom in the reporting section:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<rulesets>
<ruleset>http://serverxxx/pmd-java.xml</ruleset>
</rulesets>
<targetJdk>1.6</targetJdk>
</configuration>
</plugin>
somehow it doesn't work. When I use the rules directly instead of a custom ruleset via http it work fine. I use pmd:pmd and the section is also in the build section of the pom...
Logs:
16:11:05 [INFO] --- maven-pmd-plugin:2.7.1:cpd (default-cli) # online-news ---
16:11:05 mojoSucceeded org.apache.maven.plugins:maven-pmd-plugin:2.7.1(default-cli)
16:11:05 [DRY] Finding all files that match the pattern cpd.xml
16:11:05 [DRY] Parsing 1 files in D:\build\hudson\jobs\xxx migration-maven-3 CI\workspace\migration-maven-3\application\online-modules\online-news\target
16:11:06 [DRY] Successfully parsed file D:\build\hudson\jobs\xxx migration-maven-3 CI\workspace\migration-maven-3\application\online-modules\online-news\target\cpd.xml of module News with 31 warnings.
16:11:06 [DRY] Computing warning deltas based on reference build #13
16:11:06 mojoStarted org.codehaus.mojo:findbugs-maven-plugin:2.5.2(default-cli)