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

后端 未结 4 864
执笔经年
执笔经年 2021-01-03 21:05

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

相关标签:
4条回答
  • 2021-01-03 21:34

    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*/**
    
    0 讨论(0)
  • 2021-01-03 21:38

    If project does not follow default Maven directory structure then in project's pom you can explicitly specify where is located the part of source code and the part of tests:

    <properties>
        <sonar.sources>src/main/foo</sonar.sources>
        <sonar.tests>src/test/bar</sonar.tests>
    </properties>
    
    0 讨论(0)
  • 2021-01-03 21:43

    I was seeing this can't be indexed twice error when running sonarqube Gradle task on an Android project. The issue related to files stored in app/src/debug/assets.

    I tried setting sonar.sources and sonar.tests properties to use disjointed sets but I wasn’t able to resolve the error.

    To fix the error I changed:

    property "sonar.coverage.exclusions", "**/assets/**, ..."
    

    to:

    property "sonar.exclusions", "**/assets/**, ..."
    

    in order to ignore the /assets/ directory completely.

    0 讨论(0)
  • 2021-01-03 21:59

    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

    0 讨论(0)
提交回复
热议问题