codingenious
codingenious

Reputation: 8653

Setting source for Sonar

I am using static tool Sonar for my project. Folder structure of mt project is like :

src
   com
   plugin
      com

My src folder has package like com.a.b and then plugin has com.c.f. Point to note is, package doesn't start with plugin.com.c.f.

Now when I run Sonar using :

   <property name="plugin.sonar.projectName" value="plugin" />
   <property name="plugin.sonar.projectBaseDir" value="../base/src/plugin" />
   <property name="plugin.sonar.sources" value="../../base/src/plugin" />
   <property name="project.sonar.sources" value="src" />                             //line 4
   <!-- property name="project.sonar.sources" value="src, src/plugin" / -->          //line 5

It throws, Caused by: org.sonar.squid.api.AnalysisException: The source directory does not correspond to the package declaration com.c.f.

So I commented line 4 and used line 5, But then it keeps throwing, DuplicateSourceException when no two file are same in the project(Check thrice).

Is there any other way to do this? Am I doing something wrong?

Upvotes: 0

Views: 2788

Answers (2)

Mithfindel
Mithfindel

Reputation: 4706

With your directory structure, you will probably want to setup an exclusion rule on the root project, so that the src/plugin directory will only be analyzed as part of the plugin sub-project, e.g:

<property name="project.sonar.sources" value="src"/>
<property name="project.sonar.exclusions" value="src/plugin/**"/>
<property name="plugin.sonar.sources" value="src/plugin"/>

Upvotes: 1

Jayan
Jayan

Reputation: 18459

Your directory structure is complicated. In your case "plugin" is another source directory. If you mark "src" as sources, all files under that must be taken as sources. This leads package directory mismatch. Normal compilation this is not an error. Sonar this is an error.

The directory folder is scanned recursively. When you provide src and src/plugin as sources, this probably taking sources from src/plugin two times.

You could use this an opportunity to clean the build environment(One for main build, another one for dependency).

Upvotes: 0

Related Questions