In Sonar, we just download the sonar setup and if need, change the db credentials and run the command on maven project sonar:sonar, our coding stats and bugs are are analyzed by sonar and make the good html reports. But for this we need to run sonar:sonar command. Like findbugs, its possible to integrate with maven and create reports and time of maven:install .In this LINK at 4th step explain. Is also possible with sonar for make the report on maven:install command?
Like you can see on the SonarQube documentation, we strongly advise you to first run mvn clean install and then mvn sonar:sonar separately - otherwise you can have some side effects.
However, if you want to have all this in a single run, this is a Maven-related question. You just have to bind the "sonar" goal to the "install" phase in your POM, with something like:
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
Related
I have included JMeter plugin by lazycode in my application.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.1.0</version>
<executions>
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
This runs when I use mvn verify. But, it runs all integration tests and unit tests too. I don't want this to happen. I want to run just mvn jmeter:jmeter and run performance tests.
If I run mvn jmeter:jmeter, I get
No plugin found for prefix 'jmeter' in the current project and in the plugin groups [org.sonarsource.scanner.maven, org.apache.maven.plugins, org.codehaus.mojo] available from the repositories
I don't want to configure global .m2/settings.xml. How to run it using Maven?
You are almost there, the correct Maven command to run only JMeter tests would be:
mvn jmeter:jmeter -Pjmeter
References:
Maven - Introduction to Build Profiles
JMeter Maven Plugin
Five Ways To Launch a JMeter Test without Using the JMeter GUI
I have a multimodule project with a parent pom.xml and two modules in it. Project.jar and Project.war. All the test cases are under Project.jar. When I run mvn sonar.sonar goal on the Parent pom, jacoco.exec is not getting generated and code coverage is blank. I have the following properties in the parent pom.
<properties>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
</properties>
Please help. I am using Sonarqube 4.2.
With version 2.4 of the java plugin you have to generate the coverage report before running the SonarQube analysis. You can see this page https://github.com/SonarSource/sonar-jacoco about how to do this.
For those that have a similar issue, I solved this problem slightly differently (where I'm running it from the command-line and not having Jenkins do it). I didn't have an issue with the plugins.
All these settings are defined in the parent POM. I am using the following version:
<plugin.jacoco.version>0.7.2.201409121644</plugin.jacoco.version>
The report path is slightly different, this makes it so only one jacoco.exec is created. By default Sonar will append results together if the file already exists.
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
In the pluginManagement section, I have the following plugin:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${plugin.jacoco.version}</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
Then in my plugins section I make sure the plugin is available for the entire project:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
As benzonico noted, you need to run tests prior to sonar analyzing them, which I do as follows:
mvn clean test sonar:sonar
I did not have to make any changes to the Surefire plugin (as I've had to do in the past).
I have the wsimport plugin in my project.
I would like to execute the wsimport. According to the website, the string to execute is "mvn jaxws:wsimport".
Firstly, is this string deductable from the XML ?
The artifact ID is :
<artifactId>jaxws-maven-plugin</artifactId>
and goal :
<goal>wsimport</goal>
so is the artifact-part just the substring of the artifactid leading up to "-maven-plugin" ?
..And when I execute my plugin goal "mvn jaxws:wsimport" does this completely ignore which phase I am in? Ie. is this running outside of the phase? And if no, is there a way to run this standalone?
ie. is there a way I can set the phase to none? (eg [phase]none[/phase]).
Pom code :
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>wsimport-from-jdk</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<executable>${tool.wsimport}</executable>
<wsdlUrls>
<wsdlUrl>http://WorkPC:8080/server-web/AirlineWS?wsdl</wsdlUrl>
</wsdlUrls>
<packageName>com.bluewalrus</packageName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
When you issue a command like mvn [plugin]:[goal], it launches Maven out of any lifecycle, so if you do not intend to perform that goal inside a lifecycle, but only via such commands, you shouldn't have any <execution> defined, just place <configuration> right after <version>.
About how Maven can shorten the plugin call (i.e. mvn dependency:tree instead of mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:tree), it is based on several conventions:
When no version defined, it tries to take the latest from available repositories
When the groupId is omitted, it looks among the predefined or user-defined pluginGroups to find a suitable one. See here for more information (Configuring Maven to Search for Plugins)
On the same page, you can see how plugins prefixes are used to shorten the plugin prefix, by using a prefix instead of the artifactId of the plugin. Thirdparty plugins should use [prefix]-maven-plugin construction, and it looks OK here.
And to disable the default execution of a plugin (although it might not be useful in this case), you can use this answer
I have a Java project in Eclipse, with JUnit tests in my src/test directory. I've also added a class to my tests with Caliper microbenchmarks, and I'd like to be able to run these tests from within Eclipse.
As the Caliper code is test code, I've added Caliper as a dependency in Maven in test scope. That makes it show up in the classpath when I run JUnit tests, but I can't see a way to run an arbitrary class with test dependencies in the classpath. What I tried doing was adding a new Run Configuration for a Java Application, thinking I could launch CaliperMain with the right class as a parameter, but the Caliper jar is not on the classpath and I can't see how to add it.
I don't want to move my benchmark code and dependency into the main scope, as it's test code! It seems seriously overkill to move it into a completely separate project.
You should be able to do this with the Maven Exec Plugin. For my project, I opted to make a benchmark profile that can be run with the maven command mvn compile -P benchmarks.
To configure something like this, you can add something along the lines of the following to your pom.xml, specifying scope of the classpath as test using the <classpathScope> tag:
<profiles>
<profile>
<id>benchmarks</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>caliper</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<mainClass>com.google.caliper.runner.CaliperMain</mainClass>
<commandlineArgs>com.stackoverflow.BencharkClass,com.stackoverflow.AnotherBenchmark</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Alternatively, if you'd like to specify a lot of options for caliper, it is probably easier to use the <arguments> tags:
<executions>
<execution>
<id>caliper</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<mainClass>com.google.caliper.runner.CaliperMain</mainClass>
<arguments>
<argument>com.stackoverflow.BencharkClass</argument>
<argument>--instrument</argument>
<argument>runtime</argument>
<argument>-Cinstrument.allocation.options.trackAllocations=false</argument>
</arguments>
</configuration>
</execution>
</executions>
More configuration options (like -Cinstrument.allocation.options.trackAllocations above) can be found here and more runtime options (like --instrument above) can be found here.
Then, if you are using the Eclipse m2 Maven plugin, you can right-click on your project folder and select Run as... -> Maven Build... and enter something like clean install in the Goals input box and benchmarks in the Profiles input box and click Run and you should see the output in your Eclipse console.
It's important to note that I used a local snapshot build of Caliper by checking out the source using git clone https://code.google.com/p/caliper/, which is recommended at the time of this post in order to take advantage of the latest API.
I'm having trouble debugging my jbehave tests. I cannot get maven to start the jbehave tests and stop at a breakpoint. I have this in my pom:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<version>2.0.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-maven-plugin</artifactId>
<executions>
<execution>
<id>run-scenarios-found</id>
<phase>test</phase>
<configuration>
<scenarioIncludes>
<scenarioInclude>**/scenario/**/*${test}.java</scenarioInclude>
</scenarioIncludes>
<scenarioExcludes>
<scenarioExclude>**/*Steps.java</scenarioExclude>
</scenarioExcludes>
</configuration>
<goals>
<goal>run-scenarios</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
and I have tried things like:
$ mvn -e -o -Dtest=MyTest -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787 -Xnoagent -Djava.compiler=NONE" clean test
and
$ export MVN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787 -Xnoagent -Djava.compiler=NONE" ; mvn -Dtest=MyTest clean test
I can try to use jsadebugd, but I that will probably require immaculate timing to automate, so that sounds like a suboptimal solution, and I feel like the JBehave Maven plugin should provide this functionality. Clearly I have just not found the right piece of documetation yet. Any ideas how I go about this ?
The following worked for me:
export MAVEN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787 -Xnoagent -Djava.compiler=NONE"
then start my mvn tests:
mvn install
(maven now hangs waiting for the debugger to connect)
Then start Eclipse in a remote debug session, pointing at local host, port 8787 (as above), with appropriate breakpoints set.
Wouldn't it be easier not to start the tests with maven, but rather in the IDE with JUnit? Then you can use the debugger directly? I normally do it so, that the CI server uses maven to execute JBehave, but in the IDE, I prefer a more direct way of execution.
This worked for me:
In Eclipse Run -> Debug Configurations...
Select Maven Build and click New button
Set the goals (clean very in my case) and possible parameters
Hit Debug button
mvn -e -o -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8787 -Xnoagent -Djava.compiler=NONE" integration-test
This line worked perfect for me. Setup your Jbehave project in eclipse
with the debug port (8787) and connect to the debugger quickly while mvn is waiting to connect to your eclipse project.