Can’t be indexed twice

I am having problem.
I use Sonar scan for my Android project, and it keeps failing when trying to index .xml files under res directory.

error message: File xxx/src/main/java/com/xxx/xx/xxxxxx/home/main/res/layout/xxxxxx_fragment.xml can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

Because the security team required us to scan all resource files, I cannot simply exclude the res folders.
(Problem disappears when I do sonar.excludes="**/res/**" )
I cannot find any duplicate .xml file under main & test folders.
I have tried sonar.sources=“all my source file dir paths” sonar.tests=“all my test file paths” explicitly, and it does not help.
I am quite lost. Any help?

Hi,

Welcome to the community!

You’re seeing this error because the files are being included as both source files and test files.

You don’t need to fully exclude .xml files to fix this; you just need to keep them out of one of those sets - probably tests.

Can you share your analysis configuration, and maybe we can help you tweak it?

 
Ann

sorry, i forget show my analysis configuration.

properties {
        property "sonar.projectVersion", rootProject.ext.android["versionName"]
        property "sonar.projectKey", "xxx:xx-android"
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.projectName", "xxx-android"
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.login", "xxxx"
        property "sonar.java.source", "1.8"
        property "sonar.host.url", "https://sonar.xx.xx/"
    }

The command I executed is as follows:
./gradlew -Dsonar.gitlab.ref_name=featureSonar -Dsonar.branch.name=featureSonar sonarqube

The version I am relying on is as follows:
classpath “org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7”

thanks for your reply!

Hi,

The current version of SonarScanner for Gradle is 5.1.0.4882. Can up upgrade and see if that helps?

 
Thx,
Ann

Hi,
I tried upgrading to version 5.1.0 and it worked, but this version requires java11 or above, and our project compilation needs to rely on java8. For us, we may need to make a choice.
Thx for your help.

Hi,

You can always use a later version of Java to compile down to an earlier version of Java. You want to set the target version.

 
HTH,
Ann

1 Like

thank you every much for your help. it works for me.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.