how to use jacoco using mvn command line - maven

I am looking to just run jacoco as maven target instead of running clean install
I have been using following commamd with cobertura. Is there a similar way to run the jacoco.
mvn cobertura:cobertura
Regards
Lalit Kumar

Related

Execute maven install phase without executing maven compile

Working with a multi-module project. Want to run maven commands as follows:
mvn clean compile
Then maven install phase without again executing maven compile
Not possible.
You would need to call the goals directly, phases cannot be run separately.
you can (now) skip phases by directly calling the goal via
mvn <plugin>:<goal>
e.g.
mvn compiler:compile
see this answer for details.
for install it should be mvn install:install

Why should run first mvn clean clover2:setup install clover2:clover, then: mvn sonar:sonar

Based on the question Sonar + Clover only runs on src-instrumented, it is suggested using first mvn clean clover2:setup install clover2:clover, then: mvn sonar:sonar.
Just wonder why we cannot use mvn clean clover2:setup install clover2:clover sonar:sonar?
In the past it was the recommended way to run goal sonar:sonar alone. This is no more the case since SonarQube Scanner for Maven stopped trying to run unit tests + collect coverage for you by forking a new Maven lifecycle.
General advice is now to run goals in a single command. For example mvn clean package sonar:sonar
In the case of Clover the clover:setup goal will alter the Maven Model to make all other plugins (like surefire) use instrumented classes instead of original source code. This is indeed a problem because it will prevent SonarQube to match class files. So in your case you should either stick with two separate goals, or manually configure sonar.sources to refer to original source code.
Compared the maven logs and found the possible reason:
The "mvn clean clover2:setup install clover2:clover sonar:sonar" seems having issue to find the Source dirs. The log shows it uses ${project}\target\clover\src-instrumented and ${project}\target\generated-sources\annotations as the source dirs.
If explicitly specify src/main/java, then this single command works well. The only tricky thing is why running the goals separately doesn't need to specify sonar.sources but the plugin can still find the right folder for source dirs.

Gradle equivalent for mvn clean verify

I have a project which is based on gradle .I have to run the command which is equivalent for mvn clean verify .As I am new to both gradle and maven ,and have been exposed to only 3 command of both .I want to run a gradle equivalent for mvn clean verify .I searched on websites but still have not got the answer .Can some please help me to know what will be the gradle equivalent for "mvn clean verify"
gradle clean verify
or if you are using gradle wrapper:
./gradlew clean verify

Dcucumber.options, how to have multiple tags

I am trying run cucumber tests using maven with following command
mvn test -Dcucumber.options="--tag #debug1"
This command works fine, however if i try something like following, i get error
mvn test -Dcucumber.options="--tag #debug1 #debug2"
Is there a way to pass in multiple tag names with cucumber run-time options?
To run scenarios with #debug1 and #debug2:
Old version of Cucumber-jvm:
mvn test -Dcucumber.options="--tags #debug1 --tags #debug2"
Actual version of Cucumber-jvm:
mvn test -Dcucumber.options="--tags '#debug1 and #debug2'"
To run scenarios with #debug1 or #debug2:
Old version of Cucumber-jvm:
mvn test -Dcucumber.options="--tags #debug1,#debug2"
Actual version of Cucumber-jvm:
mvn test -Dcucumber.options="--tags '#debug1 or #debug2'"
In Cucumber 6, property name has changed. Use:
mvn verify -Dcucumber.filter.tags="#debug1 or #debug2"
For me what was working with surefire plugin:
mvn clean test -D"cucumber.filter.tags=#tag1 or #tag2"
When I tried with this version:
mvn clean test -Dcucumber.filter.tags="not #MyTag"
I got this exception:
io.cucumber.core.exception.CucumberException: Failed to parse 'cucumber.filter.tags' with value '"not #MyTag"'
Caused by: io.cucumber.tagexpressions.TagExpressionException: Tag expression '"not #MyTag"' could not be parsed because of syntax error: expected operator
Little late to the party, but I am using something like:
mvn test -D tags="debug1 and debug2"
I am on Cucumber 2.4.
The # symbol is optional. You can use a tags Maven property. And you can use boolean logic to hook up multiple tags - official docs.
Reduces the amount of typing little bit.
I using this commandline to run multiple tags
mvn test -Dcucumber.options="--tags '#tag1 or #tag2' --plugin io.qameta.allure.cucumber4jvm.AllureCucumber4Jvm --plugin rerun:rerun/failed_scenarios.txt"
Cucumber version 4.2.6
In cucumber v5.X, only mvn test -Dcucumber.options="--tags '#debug1 or #debug2'"
is supported and working.
mvn test -Dcucumber.options="--tags '#debug1 and #debug2'" is not working and either scenarios won't get executed
for version 6.10.2 Cucumber and Junit 4.12
mvn test "-Dcucumber.filter.tags= (#Tag1 or #Tag2) and not #Tag3"
where "or" is equal to "and".... for no reason (thanks Cucumber...)
for cucumber 6 use: mvn clean test -D"cucumber.filter.tags=#smoke or #dev"
for cucumber 4 use: mvn clean test -D"cucumber.options.tags=#smoke or #dev"
mvn clean verify -D tags="tagName"

Ignore test cases while running maven project with sonar

I have installed sonar and trying to analyze maven based application using following command :
clean install -Dmaven.test.skip=true -Psonar sonar:sonar
still its executing test-cases.
What if I doesn't want the analysis of unit test cases?
Found the solution, added -DskipTests=true with maven command.
The full command which works for me is :
mvn clean install -DskipTests=true -Dmaven.test.failure.ignore=true sonar:sonar
-Dsonar.database=mysql
-Dsonar.jdbc.driver=com.mysql.jdbc.Driver -Dsonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
mvn sonar:sonar -Dmaven.test.skip=true
is also an option, but make sure that your unit tests ran before to have results for unit test coverage in sonar

Resources