Reputation: 153
I am using Sonarqube to optimize my code quality in my project and I tried adding it to my CI cycle on GitLab but I am getting an error. When I just run mvn sonar:sonar in my IntelliJ terminal it works, but it somehow throws an error while executed in my GitLab CI. The error is:
Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project rlstop: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property.
My gitlab-ci.yml:
stages:
- build
- test
- sonarqube
build:
script: "mvn compile"
test:
script: "mvn test"
stage: test
sonarqube:
script: "mvn sonar:sonar"
stage: sonarqube
application.properties:
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=...
spring.datasource.username=...
spring.datasource.password=...
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql = true
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.SQLServer2012Dialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update
sonar.java.binaries=bin
Does anybody know what this error means and how to resolve it?
Upvotes: 0
Views: 2612
Reputation: 3392
The error mentioned that you need to provide the compiled classes of java using sonar.java.binaries
In your .gitlab-ci.yml file:
stages:
- build
- test
- sonarqube
build:
stage: build
script: "mvn compile"
test:
stage: test
script: "mvn test"
sonarqube:
stage: sonarqube
script: "mvn -U install sonar:sonar -Dsonar.projectKey=Gitlab-CI -Dsonar.projectName=Gitlab-CI -Dsonar.sources=. -Dsonar.java.binaries=**/* -Dsonar.language=java"
If in case you have added <sonar-java-binaries>target/classes</sonar-java-binaries>
in your pom.xml, please remove. Only, have the entry of maven-sonar-plugin in the plugins section of pom.xml
Hope this might help you.
Upvotes: 1