3

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.

2
  • If you have a Maven project, then you should be performing analysis with mvn sonar:sonar (after doing a compile, of course) Commented Apr 6, 2017 at 20:17
  • Thanks for quick reply. I tried mvn sonar:sonar and I see the below error: [ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar (default-cli) on project Myproject: Execution default-cli of goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar failed: A required class was missing while executing org.codehaus.mojo:sonar-maven-plugin:2.0:sonar: org/sonatype/aether/graph/DependencyFilter Thanks for the help. Commented Apr 6, 2017 at 21:47

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

Thanks for the reply. I will try to update the sonar-maven-plugin and see. I have 2.0, right now. I tried the multi modules approach for sonar scanner and the properties file was not recognized. I posted that in my initial post with the folder structure and the errors, I am seeing when I have the soanr-project.properties file in 2 different locations. Thanks for the help.
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.