Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't be indexed twice - testSourceDirectory and sourceDirectory are same

I have created performance test as a maven submodule to my main module. All the test classes are written under src/main/java and not src/test/java

I am able to package the project as jar and run it to performance test my project.

I wanted to execute mvn test. For mvn test to work I should have <testSourceDirectory> value set. As in this case I have my code in src/main/java I set this to :

<testSourceDirectory>src/main/java</testSourceDirectory>

Now mvn test works.

But the Problem is sonar build fails with error complaining: can't be indexed twice. Which is obvious as for my pom testSourceDirectory and sourceDirectory are same.

[ERROR] Failed to execute goal 
org.codehaus.mojo:sonar-maven-plugin:2.5:sonar (default-cli) 
   on project Blah: File [relative=XYZ.java, abs=/Path/XYZ.java] can't be indexed twice. 
Please check that inclusion/exclusion patterns produce 
disjoint sets for main and test files -> 

How to fix this issue?

like image 473
Amod Pandey Avatar asked Apr 24 '15 01:04

Amod Pandey


2 Answers

I was facing the same problem. Finally, solved it with help of below documentation:-

https://github.com/SonarOpenCommunity/sonar-cxx/wiki/FAQ

Q: ERROR: Caused by: File [...] can't be indexed twice.

A: In case of below error you have to verify your exclusion/inclusion properties. Please check that inclusion/exclusion patterns produce disjoint sets for source and test files

ERROR: Caused by: File [...] can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files An example could look like this:

sonar.sources=.
sonar.tests=.
sonar.test.inclusions=**/*Test*/**
sonar.exclusions=**/*Test*/**
like image 185
dira Avatar answered Nov 04 '22 23:11

dira


This is not a standard Maven usage but you can easily fix SonarQube analysis using exclusions. sonar.exclusions=src/main/java/** or sonar.test.exclusions=src/main/java/**

depending on whether you want your source files to be considered as tests or main files.

But the proper Maven way would be to put your tests in src/test/java and ackage your tests: https://maven.apache.org/guides/mini/guide-attached-tests.html

like image 20
Julien H. - SonarSource Team Avatar answered Nov 04 '22 22:11

Julien H. - SonarSource Team