Sonar properties for a multi language project when using sonar scanner maven plugin

Must-share information (formatted with Markdown):

  • which versions are you using:scanner->sonar-maven-plugin:3.8.0.2131,sonarqube version 8.6.

  • what are you trying to achieve: we are trying to scan the project(having java,javascript and css files) by specifying the sonar properties in the jenkins plugin - “invoke top level management” from the jenkins job type is of Maven Job.

  • what have you tried so far to achieve this: project structure is

 A
       B
           E 
                 src
                    main
                         java
                             *.java files
                    webapp
                        app      
                               *.js files
                    resources
                       cpp
                              *.css files
                 pom.xml
            F
      C
           G
           H
      D
          I
         J
 pom.xml

To scan the above directory structure, we have given the sonar properties as
mvn sonar:sonar
-Dsonar.host.url=sonarqubeurl
-Dsonar.sources=.
-Dsonar.inclusions=src/main/java/,src/main/webapp/app/,src/main/webapp/resources/css/**

Sonar is not scanning the files correctly. It is scanning only java files

Can you please let me know how to specify the sonar scanner properties for the above directory structure.

Hi,

I would have expected sonar.sources=. to do the trick. Did you add that and the inclusions setting at the same time? If so sonar.inclusions might be the problem - i.e. this may have something to do with what the perceived path inside a submodule is.

Can you add -Dsonar.scanner.dumpToFile=[path to file] so we can see what sonar.sources is actually resolved to by the scanner? And probably drop the inclusions setting for this test?

 
Ann

Hi Ann,

Thank you for your reply.

I have removed inclusion, and tried to execute with below property and stored in file.txt.
mvn sonar:sonar
-Dsonar.host.url=sonarqube url
-Dsonar.sources=src/main/java
-Dsonar.scanner.dumpToFile=file.txt

How do i know sonar.sources is resolved or not from file.txt.

But if specify like
mvn sonar:sonar
-Dsonar.host.url=sonarqubeurl
-Dsonar.sources=src/main/java,src/main/webapp
-Dsonar.scanner.dumpToFile=file.txt
in some of the submodule src.main/webapp is not present so sonar scanner is failing saying that A/C/G/src/main/webapp does not exist.

Could you please help me how to proceed on this.
Do i need to specify sonar properties in each pom.xml of the submodules?

Thanks

Hi,

I had hoped/assumed you should share what sonar.sources is resolved to, but okay.

It’s not clear to me at this point what you want to be analyzed, but I suggest a sonar.sources value of src. You can use exclusions to eliminate files you didn’t actually want included in the analysis.

 
Ann

Hi Ann,
I want to include all the files. As i mentioned in my first mail, Javascript and CSS files are not scanning properly.In each sub module pom.xml is present.but in some submodules i don’t have javascript files.(src/main/webapp).
Could you pelase let me know how to include sonar.sources to scan all the files(java,javascript and css files)

Directory layout:

  • A
  •    B(submodule)
    
  •        E (submodule)
    
  •              src
    
  •                 main
    
  •                      java
    
  •                          *.java files
    
  •                 webapp
    
  •                     app      
    
  •                            *.js files
    
  •                 resources
    
  •                    cpp
    
  •                           *.cssfiles
    
  •              pom.xml  (E sub module pom.xml)
    
  •         F (submodule)
    
  •             src
    
  •                  main
    
  •                       java
    
  •             pom.xml (Fsub module pom.xml)
    
  •      pom.xml(B sub module pom.xml)
    
  •   C
    
  •        G
    
  •            src
    
  •                main
    
  •                    java
    
  •           pom.xml(G submodule pom.xml)
    
  •        H
    
  •    pom.xml(C module pom.xml)
    
  •   D
    
  •       I
    
  •      J
    
  • pom.xml ( mainmodule (A) pom.xml)

Thanks

Thanks

Hi,

Uhm… that’s what sonar.sources=src - as suggested above - should do.

 
Ann

Hi Ann,
I have tried as per your suggestion. but getting below error.

-Dsonar.sources=src, .error —> file **/abcTest.java can’t be indexed twice
Please check that inclusion/exclusion patterns produce disjoint sets for main and test files.
Could you please help me on it.

Thanks

Hi,

Okay, you may need to configure a sonar.sources property per submodule. It will probably be easiest to do this in the pom.

 
Ann