【发布时间】:2021-01-27 15:51:38
【问题描述】:
我正在使用 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
有谁知道这个错误是什么意思以及如何解决它?
【问题讨论】:
-
使用
mvn compile sonar:sonar -Dsonar.java.binaries=target/classes。 -
然后我得到错误>没有文件或目录匹配'target/classes'
-
你添加了
compile吗? -
我最初尝试将
<sonar-java-binaries>target/classes</sonar-java-binaries>添加到我的 pom.xml 属性中,这给出了上一条评论中指定的错误。当我将您的解决方案放在 yml 中的脚本中时,出现以下错误:Unknown lifecycle phase ".java.binaries=target/classes". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are:1/2 -
2/2
validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy.
标签: java maven continuous-integration gitlab sonarqube