Reputation: 13258
I have a non-maven project, but I have to use Sonar to make a code analysis once. So I created a pom.xml
which works great. I see the analysis of all files and folders below my src
directoy using this pom file:
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.group.id</groupId>
<artifactId>arifactId</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>MyApplication</name>
<build>
<sourceDirectory>src</sourceDirectory>
</build>
<properties>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
</properties>
</project>
But I want to exclude one directory and all subdirectories of it. I have the two directories src/fr/
and src/com/
. I only want to have src/fr/
and exclude src/com/
.
Changing
<sourceDirectory>src</sourceDirectory>
to
<sourceDirectory>src/fr</sourceDirectory>
I get this error:
Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar
(default-cli) on project arifactId: Can not execute Sonar: Sonar is
unable to analyze file : '/Users/tim/workspace/src/fr/xxx/dao/TestClass.java':
The source directory does not correspond to the package declaration fr.xxx.dao
Upvotes: 1
Views: 1877
Reputation: 9059
Normally, the The source directory does not correspond to the package declaration
, as it told us, is an error when the package
declared at the java file does not correspond with the directory structure e.g.
package my.test.java;
public class MyTest {}
The directory should be my/test/java/MyTest.java,
please note the src is treated as a sourceDirectory.
In your case you have changed the sourceDirectory
from src
to src/fr
that means
package fr.xxx.dao;
public class TestClass{}
The directory is xxx/dao/TestClass.java,
please note the src/fr is treated as a sourceDirectory. Then the fr is ignored.
Normally when we would like to exclude somes package from the Sonar analysis, it can be simply done by setting them at each quality maven plugin e.g. findbugs
,PMD
, cobertura
, etc.
Anyhow the Sonar also provides the configuration for each project as well. We can set by using the following steps: -
https://myhost/sonar
Configuration
menu. Click it and select Settings
.Settings
page, select Exclusions
menu.Exclusions
you can simply set the excluded modules which is able to use the wildcard as well. (You may see the example at the bottom of the page.)fr/**
. (Exclude all under the folder fr).Please refer to the following link: -
I hope this may help.
Upvotes: 2