I'm trying to mavenize a project. The code base is beginning to bloat and it needs to be split into multiple modules. However, we already have a somewhat proprietary deployment process in place and the directory structure cannot be compromised in favor of the Maven way.
The simplified structure is as follows:
/workspace/basesrc/
|_ superpom.xml
|_ com/company/parentpkg/
|_ ModuleA/
|_ pom.xml
|_SubAModuleA/
|_ SubAModuleAClass.java
|_ pom.xml
|_SubAModuleB/
|_ SubAModuleBClass.java
|_ pom.xml
|_ ModuleB/
|_ ModuleBClass.java
|_ pom.xml
I was able to build the project using the following setup:
Approach A
(superpom.xml):
<build>
<sourceDirectory>.</sourceDirectory>
</build>
This is inherited by the submodules, in effect building only its current directory.
However, Sonar seems to have trouble resolving package names if this is the case as stated in this thread: mvn sonar:sonar throws exception while doing Java AST scan.
Approach B: Specify the root source directory and use maven compiler inclusions, as explained here: http://maven.apache.org/guides/mini/guide-using-one-source-directory.html
(superpom.xml)
<build>
<sourceDirectory>/workspace/basesrc/</sourceDirectory>
</build>
(SubAModuleA pom.xml)
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<includes><include>com/company/parentpkg/ModuleA/SubAModuleA/**/*.java</include></includes>
</configuration>
</plugin>
</plugins>
</build>
Again, this works for the case of maven build. But Sonar seems to include the whole /workspace/basesrc/
folder despite running mvn sonar:sonar
from a submodule directory.
SO my question is,
If I use Approach A, is there a way to configure/override the root directory property in which Sonar Maven Plugin is searching for Java source files? Can it be different from the ${project.build.sourceDirectory} maven property?
Using Approach B, How can Sonar be configured to analyze only what is being built by maven-compiler-plugin?