Skip to content

Instantly share code, notes, and snippets.

@vegaasen
Last active September 20, 2017 18:35
Show Gist options
  • Save vegaasen/838c57a6ecdfa2077ecb43ea0f3c6a1f to your computer and use it in GitHub Desktop.
Save vegaasen/838c57a6ecdfa2077ecb43ea0f3c6a1f to your computer and use it in GitHub Desktop.
Adding SONAR to maven

Configuration

Add the following to the pom.xml-file:

 <plugins> 
	... 
	<plugin>  
	  <groupId>org.codehaus.mojo</groupId>  
	  <artifactId>sonar-maven-plugin</artifactId>  
	  <version>3.3.0.603</version> 
	</plugin> 
	... 
</plugins> 
<properties> 
	...  
	<sonar.host.url>http://<hostname>/sonar</sonar.host.url>  
	<sonar.junit.reportsPath>target/surefire-reports</sonar.junit.reportsPath> 
	... 
</properties>

Execute sonar runner

mvn clean install sonar:sonar

Dependencies

Requires SureFire to exists in the classpath/buildroutine. Example-configuration:

<?xml version="1.0" encoding="UTF-8"?>
<profiles>
   <profile>
	  <id>default</id>
	  <build>
		 <plugins>
			<plugin>
			   <groupId>org.apache.maven.plugins</groupId>
			   <artifactId>maven-surefire-plugin</artifactId>
			   <version>${plugin.surefire.version}</version>
			   <configuration>
				  <excludes>
					 <exclude>**/**/*IntTest.java</exclude>
					 <exclude>**/**/*CtxTest.java</exclude>
				  </excludes>
				  <includes>
					 <include>**/*Test.java</include>
				  </includes>
			   </configuration>
			</plugin>
		 </plugins>
	  </build>
	  <activation>
		 <activeByDefault>true</activeByDefault>
	  </activation
   </profile>
</profiles>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment