简体   繁体   中英

Sonar: Multi-module analysis sonar

For our code analysis I want for each maven module one sonar project. At the moment I got one sonar project with the modules from parent pom.

For my Jenkins job configuration I use SonarQube Scanner for Maven ( link ) with sonar-project.properties .

# Root project information
sonar.projectKey=org.mycompany.myproject
sonar.projectName=My Project
sonar.projectVersion=1.0

# Some properties that will be inherited by the modules
sonar.sources=src

# List of the module identifiers
sonar.modules=module1,module2

So the expect result for my sonar would be a project one for module1 and a project two for module2 . module1 and module2 are both maven module with one parent pom.

  myproject
   |
    ->module1
      |
       ->pom.xml (Sonar Project ONE)
    ->module2
      |
       ->pom.xml (Sonar Project TWO)
  ->pom.xml

What is the best way to configure this behaviour in one jenkins job.

If you want to store all modules as standalone projects, then you cannot specify sonar.modules and use SonarQube Scanner for Maven. The Maven scanner is designed to create submodules (the same structure as defined in pom.xml files).

What you can to do:

  1. build all modules by Maven
  2. generate in every module's root directory a sonar-project.properties file with content:

     sonar.projectKey=<project.groupId>:<project.artifactId> sonar.projectName=<project.name> sonar.projectVersion=<project.version> sonar.sourceEncoding=<project.build.sourceEncoding> sonar.sources=pom.xml,src/main sonar.tests=src/test sonar.java.binaries=<project.build.directory>/classes sonar.java.libraries=<list of all compile and provided libraries> sonar.java.test.binaries=<project.build.directory>/classes sonar.java.test.libraries=<list of all compile, provided and test libraries> 
  3. execute SonarQube Scanner : sonar-scanner

This is very not recommended because:

  • makes your project less readable (modules are not "connected")
  • executing an analysis is much harder (you have to generate all properties which in standard cases are generated by SonarQube Scanner for Maven)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM