在GitLab CI中运行SonarQube时出错。

huangapple go评论70阅读模式
英文:

Error in running sonarqube from GitLab CI

问题

我正在使用Sonarqube来优化我的项目中的代码质量,并尝试将其添加到GitLab上的CI循环中,但是我遇到了一个错误。当我在IntelliJ终端中运行mvn sonar:sonar时,它可以正常工作,但是在GitLab CI中执行时却出现错误。错误信息如下:

在项目rlstop上执行目标org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar(default-cli)时失败:您的项目包含.java文件,请使用sonar.java.binaries属性提供编译后的类,或使用sonar.exclusions属性从分析中排除这些文件。

我的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

有人知道这个错误是什么意思以及如何解决吗?

英文:

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?

答案1

得分: 1

错误提到您需要使用 sonar.java.binaries 提供已编译的 Java 类。

在您的 .gitlab-ci.yml 文件中:

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";

如果您在 pom.xml 中添加了 <sonar-java-binaries>target/classes</sonar-java-binaries>,请删除它。只需在 pom.xml 的插件部分中保留 maven-sonar-plugin 的条目。

希望这能对您有所帮助。

英文:

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: &quot;mvn compile&quot;
test:
  stage: test
  script: &quot;mvn test&quot;
sonarqube:
  stage: sonarqube
  script: &quot;mvn -U install sonar:sonar -Dsonar.projectKey=Gitlab-CI -Dsonar.projectName=Gitlab-CI -Dsonar.sources=. -Dsonar.java.binaries=**/* -Dsonar.language=java&quot;

If in case you have added &lt;sonar-java-binaries&gt;target/classes&lt;/sonar-java-binaries&gt; 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.

huangapple
  • 本文由 发表于 2020年10月13日 18:01:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/64332998.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定