Cannot be indexed twice - testSourceDirectory and sourceDirectory are the same

I created a performance test as a maven submodule for my main module. All test classes are written in the src / main / java section, not src / test / java

I can pack the project as a jar and run it to test the performance of my project.

I wanted to run mvn test . For mvn test to work, I must have a value of <testSourceDirectory> . As in this case, I have the code in src / main / java that I installed for this:

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

Now mvn test works.

But the problem is that building a sonar is not a mistake: can't be indexed twice . Which is obvious, since my pom testSourceDirectory and sourceDirectory 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 problem?

+13
source share
3 answers

I ran into the same problem. Finally solved this using the following documentation: -

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

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

A: In case of an error below, you must confirm your exception / inclusion of the property. Please verify that inclusion / exclusion patterns produce unrelated sets for source and test files.

ERROR: Reason: the file [...] cannot be indexed twice. Please check this inclusion / exclusion patterns create disjoint sets for the main and test files. An example might look like this:

 sonar.sources=. sonar.tests=. sonar.test.inclusions=**/*Test*/** sonar.exclusions=**/*Test*/** 
+12
source

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

depending on whether you want the source files to be seen as tests or core files.

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

+4
source

If the project does not match the Maven default directory structure, in the project pom you can explicitly indicate where part of the source code and part of the tests are:

 <properties> <sonar.sources>src/main/foo</sonar.sources> <sonar.tests>src/test/bar</sonar.tests> </properties> 
0
source

All Articles