DEV Community

Pratik Pathak
Pratik Pathak

Posted on • Originally published at pratikpathak.com on

[Solved] “ERROR: File xxx can’t be indexed twice.”

This is the error you probably will be facing if you are using azure pipeline

Here’s the Sample YAML Code:

resources:
  repositories:
  - repository: Dependency
    type: githubenterprise
    endpoint: https://github.azc.ext.xxx.com
    name: cloud-client/Dependency

trigger: none

pool: 'SWindows2022-DEV'

variables:
  buildPlatform: 'x64'
  buildConfiguration: 'Release'

steps:
- checkout: self
- checkout: Dependency

- script: |
     move Dependency/KHPLib $(Build.SourcesDirectory)

- task: NuGetToolInstaller@1

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Invoke-WebRequest -Uri 'https://sq.corp.xxxcloud.net/static/cpp/build-wrapper-win-x86.zip' -OutFile 'build-wrapper.zip'
      Expand-Archive -Path 'build-wrapper.zip' -DestinationPath '.'
      Invoke-WebRequest -Uri 'https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/5.13.0.66756/sonar-scanner-msbuild-5.13.0.66756-net46.zip' -OutFile 'sonar-scanner-msbuild.zip'
      Expand-Archive -Path 'sonar-scanner-msbuild.zip' -DestinationPath './SonarScanner'

- task: VSBuild@1
  inputs:
    solution: 'KHPLib\src\KHPLib\KHPLib.vcxproj'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: SonarQubePrepare@5
  inputs:
    SonarQube: 'https://sq.corp.xxxcloud.net'
    scannerMode: 'CLI'
    configMode: 'manual'
    cliProjectKey: 'xxx_HPCEMConnectionWizardWin'
    cliSources: '.'
    extraProperties: |
      sonar.cfamily.build-wrapper-output=bw-output
      sonar.java.file.suffixes=-

- task: CmdLine@2
  inputs:
    script: |
      SonarScanner\SonarScanner.MSBuild.exe begin /k:"xxx_HPCEMConnectionWizardWin" /n:"HPCEMConnectionWizardWin\HPCEMConnectionWizardWin.sln" /v:"1.0" /d:sonar.cfamily.build-wrapper-output="bw-output"
      build-wrapper-win-x86\build-wrapper-win-x86-64.exe --out-dir bw-output "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe" HPCEMConnectionWizardWin\HPCEMConnectionWizardWin.sln -t:Rebuild /p:configuration=release /p:platform=x64
      SonarScanner\SonarScanner.MSBuild.exe end

- task: SonarQubeAnalyze@5

- task: SonarQubePublish@5
  inputs:
    pollingTimeoutSec: '300'

- task: sonar-buildbreaker@8
  inputs:
    SonarQube: 'https://sq.corp.xxxcloud.net'
Enter fullscreen mode Exit fullscreen mode

Detailed Error:

ERROR: Error during SonarScanner execution 2023-05-27T12:25:22.4759667Z File HPCEMConnectionWizardWin/src/HPCEMConnectionWizardLauncher/framework.h can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

Here is the code I like to analyze:

The C# code(*.CS) dir lists:

HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/Model/ HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/View/ HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/ViewModel/

The C++ code(.CPP,.h) dir lists:

HPCEMConnectionWizardWin/src/

verbose log: https://community.sonarsource.com/uploads/short-url/pANjC2FqXe3iqumr095tLL1TmLx.txt
Enter fullscreen mode Exit fullscreen mode

One of Developer Commented Out:

You need to check if HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config is included twice somehow. You should add sonar.verbose=true in the SonarQubePrepare step and check what files are indexed by Sonar. Then you can see where the duplication lies. Next, follow Narrowing the Focus to make sure certain files are not indexed twice.

For a quick workaround, just exclude that HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config file with:

sonar.exclusions= HPCEMConnectionWizardWin/HPCEMConnectionWizardWin/App.config
Enter fullscreen mode Exit fullscreen mode

Sonar Community Link: https://community.sonarsource.com/t/error-file-xxx-cant-be-indexed-twice-when-analyzing-a-solution-with-a-mix-of-c-and-c/91219/4

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs