How to set multiple source locations in Sonar Server?
Asked Answered
M

2

11

I'm using Maven 3 and in my java project, the pom file contains one source location as follows.

<build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <testSourceDirectory>src/test/java</testSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${JDK}</source>
                    <target>${JDK}</target>
                    <excludes>
                        <!--<exclude>**/**/api/notification/**/INotificationProfileManager.java</exclude> -->
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId>
                <configuration>
                    <version>1.3</version>
                    <archive>
                        <manifest>
                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                        <manifestEntries>
                            <Class-Path>./MubarsherTradeClasspath-1.0.jar</Class-Path>
                            <Specification-Vendor>Mubasher</Specification-Vendor>
                            <Implementation-Vendor>Mubasher</Implementation-Vendor>
                            <Sealed>false</Sealed>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>

After compiling, the generated files are located in .../generate/src/main/java/... path. When Sonar analysis is done, it checks these generated classes which themselves have a ../src/main/java/... path, so the analysis fails.

So I need to know how to define multiple source paths to analyze from sonar ?

Monochord answered 30/12, 2012 at 9:51 Comment(1)
Could you also provide the Sonar error stack trace ?Mimir
G
13

you can use sonar-runner to do that. This is more useful.

You can declare two modules. One by source directory. Then you have to configure the execution by declaring a properties file.

This file should look like this

sonar.projectKey=myproject
sonar.projectName=myprojectname
sonar.projectVersion=version
sonar.sourceEncoding=UTF-8


sonar.modules=normalsource-module, generated-module


normalsource-module.sonar.projectName=Normal Sources Module
normalsource-module.sonar.language=java
normalsource-module.sonar.sources=src/main/java
normalsource-module.sonar.binaries=target/classes
normalsource-module.sonar.projectBaseDir=.


generated-module.sonar.projectName=Generated Sources Module (Java)
generated-module.sonar.language=java
generated-module.sonar.sources=src/main/java
generated-module.sonar.binaries=target/classes
generated-module.sonar.projectBaseDir=.

Hope this helps,

Regards

Gil answered 18/7, 2013 at 13:28 Comment(2)
This is not a good way if you try to analyze a project with 50+ modules. Is there any generic approach to add source folders in a maven multi-module project? I'd like to keep using the maven-scanner instead of the sonar-scanner.Freckly
Any improvement on this? I have the same issueAdellaadelle
D
3

you can specify the sources with property sonar.sources and add different paths with coma separated value like below:

sonar.sources  = aap1/src/main/java,aap2,src/main/java
Diadem answered 27/8, 2021 at 13:24 Comment(1)
this does not workDisc

© 2022 - 2024 — McMap. All rights reserved.