Reputation: 383
I am working on a project to analyze the code with sonarqube in jenkins. The project structure under workspace is: /var/lib/jenkins/workspace/myproject-trunk-sonar/myproject/pom.xml, Module1, Module2, etc
My sonar-project.properties:
# Required metadata
sonar.projectKey=Myproject
sonar.projectName=Myproject
sonar.projectVersion=1.0
#Set modules IDs
sonar.modules=Module1, Module2
# Comma-separated paths to directories with sources (required)
sonar.sources=src/main/java
# Language
sonar.language=java
# Encoding of the source files
sonar.sourceEncoding=UTF-8
If I have the sonar-project.properties file under /var/lib/jenkins/workspace/myproject-trunk-sonar/myproject where my pom.xml and Modules are, I see the error below:
ERROR: Error during SonarQube Scanner execution
ERROR: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.sources
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
ERROR: SonarQube scanner exited with non-zero code: 1
If I have the sonar-project.properties file under /var/lib/jenkins/workspace/myproject-trunk-sonar, I see the error below:
ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: The base directory of the module 'Module1' does not exist: /var/lib/jenkins/workspace/myproject-trunk-sonar/Module1
at org.sonarsource.scanner.cli.Conf.setModuleBaseDir(Conf.java:180)
at org.sonarsource.scanner.cli.Conf.loadModuleConfigFile(Conf.java:172)
at org.sonarsource.scanner.cli.Conf.loadModulesProperties(Conf.java:137)
at org.sonarsource.scanner.cli.Conf.loadProjectProperties(Conf.java:111)
at org.sonarsource.scanner.cli.Conf.properties(Conf.java:59)
at org.sonarsource.scanner.cli.Main.execute(Main.java:68)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
ERROR: SonarQube scanner exited with non-zero code: 1
How can I let the sonar scanner look at the directory where the modules with java code is? When I have the properties file in the directory where the modules are it couldn't even find the properties file and complained about missing mandatory fields.
Thanks for any help.
Upvotes: 3
Views: 7492
Reputation: 383
Thanks for all the replies. I was able to resolve the issue by modifying the directory structure of my project. I removed the directory 'myproject' and placed the sonar-project.properties file where all the modules are and was able to run the scanner successfully.
Thanks for the help.
Upvotes: 2
Reputation: 238
Do a postjob Sonarqube action in jenkins. Forget sonar-project.properties. If your project is well build with maven package, sonarqube will analyse it with no problem. tell us. thx
Upvotes: 0
Reputation: 3256
To let maven run the sonar analysis you have to add the sonar-maven plugin to your pom.
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
And the run set jenkins to run maven with sonar goals mvn sonar:sonar.
About modules, the solution of the problem will depend on the code structure.
See here examples of multi-modules sonar analysis.
Upvotes: 0