Package declaration should match source file directoryjava:S1598 shows weird issue description

Sonarqube Version: Data Center Edition - Version 9.6 (build 59041)

Below is issue message on sonarqube, there is not issue in project, everything work fine. Location given here /agent/_work/2/s/ is location on host where this build is running.

This file “MyJavaFile.java” should be located in “com/vipin” directory, not in “/agent/_work/2/s/src/main/java/com/vipin”.
Get permalink
Package declaration should match source file directoryjava:S1598

Any idea what is wrong here? How do I fix this issue.

Hey there.

How are you executing analysis of the code (Using Maven? Gradle? The vanilla SonarScanner?)

Sharing your Azure DevOps Pipeline configuration (which runs the SonarQube analysis) might be helpful.

Running it using maven, here part of Azure pipeline

stages:
  - stage: Build
    displayName: 'Build & Test Stage'
    jobs:
      - job: codelintAndCoverage
        displayName: 'Sonar and WhiteSource Scanning'
        variables:
          - group: ABC
        steps:
          - task: SonarQubePrepare@4
            inputs:
              SonarQube: 'sonarqube.XXXXX.com'
              scannerMode: 'Other'
              extraProperties: |
                sonar.projectKey=XXXXX
                sonar.projectName=XXXXX
                sonar.cpd.exclusions=**/*DTO.java

          - task: Maven@3
            displayName: 'maven test'
            inputs:
              mavenPomFile: 'pom.xml'
              mavenOptions: '-Xmx3072m'
              javaHomeOption: 'JDKVersion'
              jdkArchitectureOption: 'x64'
              publishJUnitResults: true
              testResultsFiles: '**/surefire-reports/TEST-*.xml'
              mavenVersionOption: 'Default'
              mavenAuthenticateFeed: false
              effectivePomSkip: false
              codeCoverageToolOption: "JaCoCo"
              codeCoverageClassFilter: -:*.dto.*
              isJacocoCoverageReportXML: true
              sonarQubeRunAnalysis: true
              sqMavenPluginVersionChoice: 'latest'
          - task: SonarQubePublish@4
            inputs:
              pollingTimeoutSec: '300'

That’s really interesting – thanks. I’ll flag this thread for some expert attention.

My code base was messed up, intellij doesn’t show directory renaming nicely in changes. So actually I had to change directory name and commit to fix it. It was showing correct name when I deleted project and did git pull again it showed wrong package name which then I fixed. Overall you can close the issue now. Thanks.

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