Sonar against a non-maven multi-modules project


I’ve explained a few monthes ago how to run Sonar against a non-maven project.

The workaround is to create a POM with an explicit source directory and set the Sonar property sonar.dynamicAnalysis to false.

What if the project has many source folders ?

For instance a WebSphere Commerce Server project with 3 sub-projects:

  • Stores which sources are in JavaSources
  • WebSphereCommerceServerExtensionsLogic which sources are in src
  • WebSphereCommerceServerExtensionsData which sources are in ejbModule

It looks like a Maven project with 3 modules, each module having a non standard source folder.

Step 1: The main POM

First of all, make a new directory besides the project root folder and create the main POM file.

Your directories now looks like

  • Project
    • Stores
    • WebSphereCommerceServerExtensionsLogic
    • WebSphereCommerceServerExtensionsData
  • MavenProject
    • pom.xml


pom.xml


<project xmlns= »http://maven.apache.org/POM/4.0.0&Prime;
xmlns:xsi= »http://www.w3.org/2001/XMLSchema-instance &raquo;
xsi:schemaLocation= »http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd »&gt;

<modelVersion>4.0.0</modelVersion>

<!–  project information –>

<groupId>my-commerce-web-site</groupId>
<artifactId>my-commerce-web-site</artifactId>
<name>My Commerce Site Project</name>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<build>

<!– Setup compiler options Java 1.4 –>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.4</source>
<target>1.4</target>
</configuration>
</plugin>
</plugins>

</build>

<modules>

<module>ExtensionsData</module>
<module>ExtensionsLogic</module>
<module>Stores</module>

</modules>

<properties>

<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>

</properties>

<pluginRepositories>

<!– Sonar may not be found on some repositories –>
<pluginRepository>
<id>Codehaus repository</id>
<url>http://repository.codehaus.org/</url&gt;
</pluginRepository>

</pluginRepositories>

</project>


Step 2: Modules directories

Create a directory  for each modules with respect to the module’s  names  in the main  pom.xml

Your directories now looks like

  • MavenProject
    • pom.xml
    • Stores
    • ExtensionsLogic
    • ExtensionsData

Step 3: Module’s POMs

Create the module’s pom.xml for each module.

Stores/pom.xml


<project xmlns= »http://maven.apache.org/POM/4.0.0&Prime;
xmlns:xsi= »http://www.w3.org/2001/XMLSchema-instance &raquo;
xsi:schemaLocation= »http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd »&gt;

<modelVersion>4.0.0</modelVersion>

<!–  project information –>
<groupId>my-commerce-web-site</groupId>
<artifactId>my-commerce-web-site-stores</artifactId>
<name>MyCommerceSite Stores</name>
<version>0.0.1-SNAPSHOT</version>
<parent>

<groupId>my-commerce-web-site</groupId>
<artifactId>my-commerce-web-site</artifactId>
<version>0.0.1-SNAPSHOT</version>

</parent>

<build>

<sourceDirectory>../../Project/Stores/JavaSource</sourceDirectory>
<outputDirectory>target/classes</outputDirector>

</build>

</project>


Parent’s groupId and artifactId should match the main pom’s groupId and artifactId.

Your directories now looks like

  • MavenProject
    • pom.xml
    • Stores
      • pom.xml
    • ExtensionsLogic
    • ExtensionsData


Similar posts:

2 réflexions sur “Sonar against a non-maven multi-modules project

  1. Thank you for the instructions. It helped me to build successfully my project. But I have a problem with sonar & hudson: they build the sources but don’t run the test classes. Here’s the structure of my project:

    MyProject
    – pom.xml
    – group1
    – group2
    + branch1
    – subProject1
    + pom.xml
    + src
    – main
    – test
    + target
    – subProject2

    Hudson show just; … BUILD SUCCESS but there’s no TEST
    Sonar doesn’t see show any line of code

    Could you please help me solving the problem? Thanks in advance

Répondre

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion /  Changer )

Photo Google

Vous commentez à l'aide de votre compte Google. Déconnexion /  Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s