Is the maven surefire plugin needed to run unit tests when using the mvn clean test command?
I read the documentation and know it says that:
The Surefire Plugin is used during the test phase of the build
lifecycle to execute the unit tests of an application. It generates
reports in two different file formats:
Plain text files (.txt) XML files (.xml) By default, these files are
generated at ${basedir}/target/surefire-reports.
However, I ran the tests without using the surefire plugin and they all passed.
no not needed but it is used by maven per default. if you have a better plugin you can change it. but i would prefer the defaults.
the maven-surfire-plugin is bound to the test phase of the default lifecycle. the maven-surfire-plugins runs all Tests matches the filename pattern Test*.java, *Test.java und *TestCase.java reside in the directory src/test/java.
for more information have a look at http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html
you can verify this on the console output... here is the tailed output of mvn test...:
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # rechnungsverwaltung ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # rechnungsverwaltung ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.447 s
[INFO] Finished at: 2015-10-17T22:36:59+02:00
[INFO] Final Memory: 18M/304M
[INFO] ------------------------------------------------------------------------
Hava a look at the line. there you can see that the maven-surefire-plugin is used
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) #
Related
I am getting the below error while i was trigger build job in jenkins .there is no change from last build to this build but i am getting this error .
please help me
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # avsbe-web-ca ---
[INFO] Deleting /root/.jenkins/workspace/CA-16_PORTAL_BE-NG-WEB/16-PORTAL_BE/avsbe-web-ca/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # avsbe-web-ca ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) # avsbe-web-ca ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 40 source files to /root/.jenkins/workspace/CA-16_PORTAL_BE-NG-WEB/16-PORTAL_BE/avsbe-web-ca/target/classes
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE
Follow below steps to solve problem. Its work for me.
Uninstall you maven from running environment.
Install Maven form :
wget http://www-eu.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
Extract tar file using:
tar -zxvf apache-maven-3.3.9-bin.tar.gz
Now set M2_HOME in environment. Open vi /etc/profile
End of file add below lines and save file.
export M2_HOME=/opt/apache-maven-3.3.9/
export M2="$M2_HOME"bin
export PATH=$PATH:$M2
Compile this file using source /etc/profile command.
Your Maven home path is set. Yo can check using echo $M2_HOME command.
Not set /opt/apache-maven-3.3.9/ as a Maven path on jenkins.
Run your project from jenkis.
Using SonarQube 6.3, sonar-maven-plugin 3.3.0.660, Java 8, on a multi-module Maven project.
On the source files, code coverage (with JaCoCo) is working well, as are the analysis plugins, duplication detection, test executions and duration etc. But, we have no metrics for test files. The files are being loaded into SonarQube, but Lines of Code and Duplications are blank (as is Coverage but that one makes sense), while Bugs, Vulnerabilities, and Code Smells are all 0. We may have something configured incorrectly but I can't figure out what.
Example: one module contains Java and XML source and test files. The sonar properties in the POM are:
<sonar.sources>.</sonar.sources>
<sonar.inclusions>src/main/**/*,src/app/**/*,**/*.xml,**/*.properties,**/*.json</sonar.inclusions>
<sonar.tests>.</sonar.tests>
<sonar.test.inclusions>src/test/**/*,e2e/**/*</sonar.test.inclusions>
In SonarQube --> Administration --> Analysis Scope, we have Import Unknown Files enabled. We also have the property sonar.global.exclusions set to target/**/*
When running an analysis with the Maven plugin, we see messages like this in logs:
[INFO] 13:01:35.726 Base dir: /JENKINS_WS/project/module
[INFO] 13:01:35.726 Working dir: /JENKINS_WS/project/module/target/sonar
[INFO] 13:01:35.726 Source paths: .
[INFO] 13:01:35.726 Test paths: .
[INFO] 13:01:35.726 Source encoding: UTF-8, default locale: en_US
[INFO] 13:01:35.726 Index files
[INFO] 13:01:35.726 Included sources:
[INFO] 13:01:35.726 src/main/**/*
[INFO] 13:01:35.726 src/app/**/*
[INFO] 13:01:35.726 **/*.xml
[INFO] 13:01:35.726 **/*.properties
[INFO] 13:01:35.727 **/*.json
[INFO] 13:01:35.727 Excluded sources:
[INFO] 13:01:35.727 target/**/*
[INFO] 13:01:35.727 src/test/**/*
[INFO] 13:01:35.727 e2e/**/*
[INFO] 13:01:35.727 Included tests:
[INFO] 13:01:35.727 src/test/**/*
[INFO] 13:01:35.727 e2e/**/*
...
It appears that files in the test directories are being indexed properly:
[DEBUG] 13:01:35.778 'src/test/resources/log4j.xml' indexed as test with language 'xml'
[DEBUG] 13:01:35.779 'src/test/resources/appContext-test.xml' indexed as test with language 'xml'
[DEBUG] 13:01:35.779 'src/test/java/com/company/module/EnvEchoTest.java' indexed as test with language 'java'
And the Java scanner reports that the single test file was analyzed too:
[INFO] 13:01:38.520 Java Test Files AST scan
[INFO] 13:01:38.520 1 source files to be analyzed
[DEBUG] 13:01:38.521 'src/test/java/com/company/module/EnvEchoTest.java' generated metadata as test with charset 'UTF-8'
[DEBUG] 13:01:38.529 ----- Classpath analyzed by Squid:
[DEBUG] 13:01:38.529 /JENKINS_WS/project/module/target/test-classes
[DEBUG] 13:01:38.529 /JENKINS_WS/project/module/target/classes
... snip printing all the jar file debug msgs ....
[INFO] 13:01:38.567 1/1 source files have been analyzed
[INFO] 13:01:38.567 Java Test Files AST scan (done) | time=47ms
But the metrics are not populated in SonarQube. Can anyone provide pointers?
All is well. Or at least working as designed.
SonarQube is designed to report on the quality of your code, and tests aren't really considered to be code. They're... supporting files.
That said, there is a set of rules written specifically to examine the quality of your tests as tests. If included in your profile, they might raise issues on your tests. But so-called normal rules won't be run against tests, and metrics will not be calculated.
If you really want those things, you'll need to set up a separate, second analysis of your project, where the sonar.sources property points to the tests directory.
I am having a problem regarding aggregating the data of a multi-module maven project in a single store directory using -Djqassistant.useExecutionRootAsProjectRoot=true.
Here is how my project is structured
root-project [NO PARENT]
----/project-A [PARENT company-parent-pom-A]
----/project-B [PARENT company-parent-pom-B]
I am running the following on the root project
mvn clean install -DskipTests=true com.buschmais.jqassistant:jqassistant-maven-plugin:1.2.0:scan -Djqassistant.useExecutionRootAsProjectRoot=true
But it shows following error.
Failed to execute goal com.buschmais.jqassistant:jqassistant-maven-plugin:1.2.0:scan (default-cli) on project root-project: Cannot re-use store instance from reactor. Either declare the plugin as extension or execute Maven using the property -Djqassistant.store.lifecycle=MODULE on the command line.
So I add -Djqassistant.store.lifecycle=MODULE and run the following
mvn clean install -DskipTests=true com.buschmais.jqassistant:jqassistant-maven-plugin:1.2.0:scan -Djqassistant.useExecutionRootAsProjectRoot=true -Djqassistant.store.lifecycle=MODULE
Now the build succeeds. But while scanning the root-project in the end the plugin resets the store directory. So all the data collected before gets removed. Is this an issue of jqa-maven-plugin or am I doing something wrong?
19984 [INFO] --- jqassistant-maven-plugin:1.2.0:scan (default-cli) # project-B ---
22034 [INFO] Loaded jQAssistant plugins [Common, Core Analysis, JUnit, Java, Maven 3, XML].
22082 [INFO] Opening store in directory '/home/mehedi/Develop/WorkSpace/jqa-projects/test-project/target/jqassistant/store'.
24227 [INFO] Resetting store.
27464 [INFO] Reset finished.
28887 [INFO] Entering /home/mehedi/Develop/WorkSpace/jqa-projects/test-project/project-B/target/classes
29861 [INFO] Leaving /home/mehedi/Develop/WorkSpace/jqa-projects/test-project/project-B/target/classes (183 entries, 972 ms)
29864 [INFO] Entering /home/mehedi/Develop/WorkSpace/jqa-projects/test-project/project-B/target/test-classes
29874 [INFO] Leaving /home/mehedi/Develop/WorkSpace/jqa-projects/test-project/project-B/target/test-classes (12 entries, 10 ms)
30823 [INFO] Closing store in directory '/home/mehedi/Develop/WorkSpace/jqa-projects/test-project/target/jqassistant/store'.
...
124415 [INFO] --- jqassistant-maven-plugin:1.2.0:scan (default-cli) # project-A ---
124423 [INFO] Opening store in directory '/home/mehedi/Develop/WorkSpace/jqa-projects/test-project/target/jqassistant/store'.
124971 [INFO] Entering /home/mehedi/Develop/WorkSpace/jqa-projects/test-project/project-A/target/classes
124973 [INFO] Leaving /home/mehedi/Develop/WorkSpace/jqa-projects/test-project/project-A/target/classes (2 entries, 1 ms)
125222 [INFO] Closing store in directory '/home/mehedi/Develop/WorkSpace/jqa-projects/test-project/target/jqassistant/store'.
...
138156 [INFO] --- jqassistant-maven-plugin:1.2.0:scan (default-cli) # root-project ---
139411 [INFO] Loaded jQAssistant plugins [Common, Core Analysis, JUnit, Java, Maven 3, XML].
139448 [INFO] Opening store in directory '/home/mehedi/Develop/WorkSpace/jqa-projects/test-project/target/jqassistant/store'.
140780 [INFO] Resetting store.
146562 [INFO] Reset finished.
147842 [INFO] Closing store in directory '/home/mehedi/Develop/WorkSpace/jqa-projects/test-project/target/jqassistant/store'.
The setup you're describing should be working so likely you found a bug. Can you report this please on https://github.com/buschmais/jqa-maven-plugin?
Maven provides a way to show a list of all resolved dependencies with mvn dependency:list:
[INFO] The following files have been resolved:
[INFO] org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO] org.hibernate:hibernate-core:jar:5.2.3.Final:compile
[INFO] javax.inject:javax.inject:jar:1:compile
[INFO] javax.annotation:jsr250-api:jar:1.0:compile
[INFO] org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] org.jboss:jandex:jar:2.0.0.Final:compile
[INFO] com.fasterxml:classmate:jar:1.3.0:compile
[INFO] org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:com:compile
[INFO] javax.el:el-api:jar:2.2:compile
[INFO] org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
Gradle's dependency report is in a tree structure, which makes it difficult to clearly see version is finally used.
Is there a command or something that gives me this list of the resolved dependencies without the tree structure?
If you execute the followin at the command line (in your gradle project dir)
gradle tasks
You'll see the following in the list
Help tasks
----------
dependencies - Displays all dependencies declared in root project 'xyz'.
dependencyInsight - Displays the insight into a specific dependency in root project 'xyz'
More info here
I have a Jenkins+Nexus installation, and some project there that are automated.
Jenkins deploy the sources and javadocs to nexus in the deploy phase (I am using Maven Release) -- Javadoc could be ok but I don't want to have any sources in Nexus.
I was searching and googling and I don't know how to skip this step.
Thanks a lot
Output from jenkins
[INFO] [INFO]
[INFO] [INFO] --- maven-install-plugin:2.3.1:install (default-install) # projectA ---
[INFO] [INFO] Installing /var/lib/jenkins/jobs/MyBuild/workspace/target/checkout/MyProject/projectA/target/projectA-1227.jar to .../projectA-1227.jar
[INFO] [INFO] Installing /var/lib/jenkins/jobs/MyBuild/workspace/target/checkout/MyProject/projectA/pom.xml to .../projectA-1227.pom
[INFO] [INFO] Installing /var/lib/jenkins/jobs/MyBuild/workspace/target/checkout/MyProject/projectA/target/projectA-1227-sources.jar to .../projectA-1227-sources.jar
[INFO] [INFO] Installing /var/lib/jenkins/jobs/MyBuild/workspace/target/checkout/MyProject/projectA/target/projectA-1227-javadoc.jar to .../projectA-1227-javadoc.jar
[INFO] [INFO]
Try adding : -Darguments="-Dsource.skip=true -Dmaven.javadoc.skip=true"
to your maven release plugin config (Jenkins > your build configuration > Maven release build > Release goals and options
By default this actually does not happen automatically. Most likely you have configured a release profile somewhere in your pom hierarchy that adds the Maven Source Plugin execution.
You could remove that if you never want to use it or otherwise change the release plugin config to use a different profile or skip source creation or invoke the build with parameters to skip as Guilame has answered