I don’t think there is a java developer in this world who hasn’t hears of Sonar, the most effective tool that shows your coding mistakes and bad practices and help you improve your coding and the design of your code.
A few months ago I decided to introduce Sonar to the team I am working with now. The project is quite old and after switching the build system from Ant to Maven (I am preparing a post about this too, but it will take a while) integration with Sonar became really easy to do so I did it. According to the specifications on their site all I had to do, is install and start Sonar and then add the plugin in my pom.xml and configure the plugin in order to tell it where Sonar is, what database uses an the credentials for it. I was using Maven 3.0.5 so the correct way to go was to add this plugin to my pom.xml (according to the documentation on their site):
<build> <pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>2.0</version> </plugin> <plugins> </pluginManagement> </build>
But at some point Intellij started complaining that the plugin cannot be found anymore. So I started investigating. I noticed that the latest version of Sonar was 3.5.1, so I thought that the same version for the plugin was available. And it was so I proceeded in modifying my pom.xml:
<build> <pluginManagement> <plugins> <plugin> <groupId>org.codehaus.sonar</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>3.5.1</version> </plugin> <plugins> </pluginManagement> </build>
Yes, the groupId was changed, but this was no problem. Intellij was still complaining that the plugin cannot be found and when building from the command line, the plugin could not be downloaded. So something was really wrong. So I had to tell maven where to find the plugin, because apparently it was not on the public repository. So I started searching for the plugin, to see if it is available on any other public repository and I found it here. So what I had to do was to edit my settings.xml configuration file for Maven (you can find it in M2_HOME/conf) and add that repository:
<profile> <id>default</id> <repositories> <repository> <id>maven-default-repo-1</id> <name>Maven default repo(1)</name> <url>http://repo1.maven.org/maven2</url> </repository> <repository> <id>maven-default-repo</id> <name>Maven default repo</name> <url>http://repo.maven.apache.org/maven2/</url> </repository> [...] <!-- other repositories --> </repositories> </profile>