spring - 未知生命周期阶段 ".qualitygate.wait=true"

标签 spring maven sonarqube yaml gitlab-ci

我正在尝试将 SonarQube 与 GitLab CI 集成,但出现以下错误:

[ERROR] Unknown lifecycle phase ".qualitygate.wait=true". 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: 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

我有一个带有 Maven 的 Spring Boot 项目。 我像文档中一样编辑了 Maven settings.xml 以在其中添加 Sonar 。

这是我的日志文件:

Running with gitlab-runner 13.3.1 (738bbe5a)
  on Default runner 77Lxte6S
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:00
Running on DESKTOP-CMAC9J3...
Getting source from Git repository
00:02
Fetching changes...
Reinitialized existing Git repository in C:/Fontys/CI Runner/builds/77Lxte6S/0/I426015/its_georgi_manev_s3/.git/
Checking out 6fddf4a4 as master...
Removing target/
git-lfs/2.9.2 (GitHub; windows amd64; go 1.12.7; git 0274d856)
Skipping Git submodules setup
Restoring cache
Version:      13.3.1
Git revision: 738bbe5a
Git branch:   13-3-stable
GO version:   go1.13.8
Built:        2020-08-25T12:29:07+0000
OS/Arch:      windows/386
Checking cache for sonarqube-check...
Runtime platform                                    arch=386 os=windows pid=14048 revision=738bbe5a version=13.3.1
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
Executing "step_script" stage of the job script
00:23
$ mvn verify sonar:sonar -Dsonar.qualitygate.wait=true
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------------< com.its:ITS >-----------------------------
[INFO] Building ITS 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ ITS ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ ITS ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to C:\Fontys\CI Runner\builds\77Lxte6S\0\I426015\its_georgi_manev_s3\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ ITS ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Fontys\CI Runner\builds\77Lxte6S\0\I426015\its_georgi_manev_s3\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ ITS ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Fontys\CI Runner\builds\77Lxte6S\0\I426015\its_georgi_manev_s3\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ ITS ---
[INFO] 

[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ ITS ---
[INFO] Building jar: C:\Fontys\CI Runner\builds\77Lxte6S\0\I426015\its_georgi_manev_s3\target\ITS-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.3.4.RELEASE:repackage (repackage) @ ITS ---
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] ----------------------------< com.its:ITS >-----------------------------
[INFO] Building ITS 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- sonar-maven-plugin:3.7.0.1746:sonar (default-cli) @ ITS ---
[INFO] User cache: C:\Fontys\CI Runner\builds\77Lxte6S\0\I426015\its_georgi_manev_s3\.sonar\cache
[INFO] SonarQube version: 8.5.0
[INFO] Default locale: "en_US", source code encoding: "UTF-8"
[INFO] Load global settings
[INFO] Load global settings (done) | time=87ms
[INFO] Server id: BF41A1F2-AXUskNJ7IDe8fi-slcI-
[INFO] User cache: C:\Fontys\CI Runner\builds\77Lxte6S\0\I426015\its_georgi_manev_s3\.sonar\cache
[INFO] Load/download plugins
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=55ms
[INFO] Load/download plugins (done) | time=106ms
[INFO] Process project properties
[INFO] Process project properties (done) | time=10ms
[INFO] Execute project builders
[INFO] Execute project builders (done) | time=3ms
[INFO] Project key: com.its:ITS
[INFO] Base dir: C:\Fontys\CI Runner\builds\77Lxte6S\0\I426015\its_georgi_manev_s3
[INFO] Working dir: C:\Fontys\CI Runner\builds\77Lxte6S\0\I426015\its_georgi_manev_s3\target\sonar
[INFO] Load project settings for component key: 'com.its:ITS'
[INFO] Load project settings for component key: 'com.its:ITS' (done) | time=16ms
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=48ms
[INFO] Auto-configuring with CI 'Gitlab CI'
[INFO] Load active rules
[INFO] Load active rules (done) | time=1041ms
[INFO] Indexing files...
[INFO] Project configuration:
[INFO] 8 files indexed
[INFO] 0 files ignored because of scm ignore settings
[INFO] Quality profile for java: Java NO CORS
[INFO] Quality profile for xml: Sonar way
[INFO] ------------- Run sensors on module ITS
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=20ms
[INFO] Sensor JavaSquidSensor [java]
[INFO] Configured Java source version (sonar.java.source): 11
[INFO] JavaClasspath initialization
[INFO] JavaClasspath initialization (done) | time=12ms
[INFO] JavaTestClasspath initialization
[INFO] JavaTestClasspath initialization (done) | time=6ms
[INFO] Java Main Files AST scan
[INFO] 6 source files to be analyzed
[INFO] Load project repositories
[INFO] Load project repositories (done) | time=14ms
[INFO] 6/6 source files have been analyzed
[INFO] Java Main Files AST scan (done) | time=1659ms
[INFO] Java Test Files AST scan
[INFO] 1 source files to be analyzed
[INFO] Java Test Files AST scan (done) | time=66ms
[INFO] 1/1 source files have been analyzed
[INFO] Java Generated Files AST scan
[INFO] 0 source files to be analyzed
[INFO] Java Generated Files AST scan (done) | time=1ms
[INFO] 0/0 source files have been analyzed
[INFO] Sensor JavaSquidSensor [java] (done) | time=1884ms
[INFO] Sensor CSS Rules [cssfamily]
[INFO] No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
[INFO] Sensor CSS Rules [cssfamily] (done) | time=2ms
[INFO] Sensor JaCoCo XML Report Importer [jacoco]
[INFO] 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
[INFO] No report imported, no coverage information will be imported by JaCoCo XML Report Importer
[INFO] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=5ms
[INFO] Sensor C# Properties [csharp]
[INFO] Sensor C# Properties [csharp] (done) | time=1ms
[INFO] Sensor SurefireSensor [java]
[INFO] parsing [C:\Fontys\CI Runner\builds\77Lxte6S\0\I426015\its_georgi_manev_s3\target\surefire-reports]
[INFO] Sensor SurefireSensor [java] (done) | time=78ms
[INFO] Sensor JavaXmlSensor [java]
[INFO] 1 source files to be analyzed
[INFO] Sensor JavaXmlSensor [java] (done) | time=185ms
[INFO] 1/1 source files have been analyzed
[INFO] Sensor HTML [web]
[INFO] Sensor HTML [web] (done) | time=4ms
[INFO] Sensor XML Sensor [xml]
[INFO] 1 source files to be analyzed
[INFO] Sensor XML Sensor [xml] (done) | time=114ms
[INFO] 1/1 source files have been analyzed
[INFO] Sensor VB.NET Properties [vbnet]
[INFO] Sensor VB.NET Properties [vbnet] (done) | time=1ms
[INFO] ------------- Run sensors on project
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=10ms
[INFO] Sensor Java CPD Block Indexer
[INFO] Sensor Java CPD Block Indexer (done) | time=24ms
[INFO] SCM Publisher SCM provider for this project is: git
[INFO] SCM Publisher 1 source file to be analyzed
[INFO] SCM Publisher 1/1 source file have been analyzed (done) | time=211ms
[INFO] CPD Executor 3 files had no CPD blocks
[INFO] CPD Executor Calculating CPD for 3 files
[INFO] CPD Executor CPD calculation finished (done) | time=7ms
[INFO] Analysis report generated in 79ms, dir size=106 KB
[INFO] Analysis report compressed in 137ms, zip size=27 KB
[INFO] Analysis report uploaded in 39ms
[INFO] ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=com.its%3AITS
[INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] More about the report processing at http://localhost:9000/api/ce/task?id=AXVAanQEcFRPLb2nDbPG
[INFO] Analysis total time: 5.924 s
[INFO] 
[INFO] ----------------------------< com.its:ITS >-----------------------------
[INFO] Building ITS 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  21.449 s
[INFO] Finished at: 2020-10-19T12:31:59+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase ".qualitygate.wait=true". 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: 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. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
ERROR: Job failed: exit status 1

仅当我运行管道时才会发生这种情况,而当我在 cmd 中运行 mvn verify sonar:sonar -Dsonar.qualitygate.wait=true 时,我不会收到任何错误。

这是来自 cmd 的日志(缩写):

[INFO] Scanning for projects...
[INFO]
[INFO] ------< com.its:ITS >---------
[INFO] Building ITS 0.0.1-SNAPSHOT
[INFO] =----------[ jar ]-------------------
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ ITS ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ ITS ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ ITS ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory E:\Eclipse IDE n gfish\eclipseWorkSpace\ddemorest\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ ITS ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ ITS ---

[INFO]
[INFO] ----------< com.its:ITS >--------
[INFO] Building ITS 0.0.1-SNAPSHOT
[INFO] ------[ jar ]---------
[INFO]
[INFO] --- sonar-maven-plugin:3.7.0.1746:sonar (default-cli) @ ITS ---
[INFO] User cache: C:\Users\Joro\.sonar\cache
[INFO] SonarQube version: 8.5.0
[INFO] Default locale: "en_US", source code encoding: "UTF-8"
[INFO] Load global settings
[INFO] Load global settings (done) | time=79ms
[INFO] Server id: BF41A1F2-AXUskNJ7IDe8fi-slcI-
[INFO] User cache: C:\Users\Joro\.sonar\cache
[INFO] Load/download plugins
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=76ms
[INFO] Load/download plugins (done) | time=154ms
[INFO] Process project properties
[INFO] Process project properties (done) | time=17ms
[INFO] Execute project builders
[INFO] Execute project builders (done) | time=4ms
[INFO] Project key: com.its:ITS
[INFO] Base dir: E:\Eclipse IDE n gfish\eclipseWorkSpace\ddemorest
[INFO] Working dir: E:\Eclipse IDE n gfish\eclipseWorkSpace\ddemorest\target\sonar
[INFO] Load project settings for component key: 'com.its:ITS'
[INFO] Load project settings for component key: 'com.its:ITS' (done) | time=20ms
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=96ms
[INFO] Load active rules
[INFO] Load active rules (done) | time=1057ms
[INFO] Indexing files...
[INFO] Project configuration:
[INFO] 8 files indexed
[INFO] 0 files ignored because of scm ignore settings
[INFO] Quality profile for java: Java NO CORS
[INFO] Quality profile for xml: Sonar way
[INFO] ------------- Run sensors on module ITS
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=21ms
[INFO] Sensor JavaSquidSensor [java]
[INFO] Configured Java source version (sonar.java.source): 11
[INFO] JavaClasspath initialization
[INFO] JavaClasspath initialization (done) | time=18ms
[INFO] JavaTestClasspath initialization
[INFO] JavaTestClasspath initialization (done) | time=8ms
[INFO] Java Main Files AST scan
[INFO] 6 source files to be analyzed
[INFO] Load project repositories
[INFO] Load project repositories (done) | time=20ms
[INFO] 6/6 source files have been analyzed
[INFO] Java Main Files AST scan (done) | time=1670ms
[INFO] Java Test Files AST scan
[INFO] 1 source files to be analyzed
[INFO] Java Test Files AST scan (done) | time=68ms
[INFO] 1/1 source files have been analyzed
[INFO] Java Generated Files AST scan
[INFO] 0 source files to be analyzed
[INFO] Java Generated Files AST scan (done) | time=6ms
[INFO] 0/0 source files have been analyzed
[INFO] Sensor JavaSquidSensor [java] (done) | time=1931ms
[INFO] Sensor CSS Rules [cssfamily]
[INFO] No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
[INFO] Sensor CSS Rules [cssfamily] (done) | time=9ms
[INFO] Sensor JaCoCo XML Report Importer [jacoco]
[INFO] 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
[INFO] No report imported, no coverage information will be imported by JaCoCo XML Report Importer
[INFO] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=21ms
[INFO] Sensor C# Properties [csharp]
[INFO] Sensor C# Properties [csharp] (done) | time=7ms
[INFO] Sensor SurefireSensor [java]
[INFO] parsing [E:\Eclipse IDE n gfish\eclipseWorkSpace\ddemorest\target\surefire-reports]
[INFO] Sensor SurefireSensor [java] (done) | time=84ms
[INFO] Sensor JavaXmlSensor [java]
[INFO] 1 source files to be analyzed
[INFO] Sensor JavaXmlSensor [java] (done) | time=153ms
[INFO] 1/1 source files have been analyzed
[INFO] Sensor HTML [web]
[INFO] Sensor HTML [web] (done) | time=7ms
[INFO] Sensor XML Sensor [xml]
[INFO] 1 source files to be analyzed
[INFO] Sensor XML Sensor [xml] (done) | time=122ms
[INFO] 1/1 source files have been analyzed
[INFO] Sensor VB.NET Properties [vbnet]
[INFO] Sensor VB.NET Properties [vbnet] (done) | time=6ms
[INFO] ---- Run sensors on project
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=14ms
[INFO] Sensor Java CPD Block Indexer
[INFO] Sensor Java CPD Block Indexer (done) | time=25ms
[INFO] CPD Executor 3 files had no CPD blocks
[INFO] CPD Executor Calculating CPD for 3 files
[INFO] CPD Executor CPD calculation finished (done) | time=9ms
[INFO] Analysis report generated in 103ms, dir size=105 KB
[INFO] Analysis report compressed in 117ms, zip size=27 KB
[INFO] Analysis report uploaded in 44ms
[INFO] ------Check Quality Gate status
[INFO] Waiting for the analysis report to be processed (max 300s)
[INFO] QUALITY GATE STATUS: PASSED - View details on http://localhost:9000/dashboard?id=com.its%3AITS
[INFO] Analysis total time: 11.358 s

[INFO] BUILD SUCCESS

这是我的 .gitlab-ci.yml 配置:

maven_build:
  stage: test
  script:
    - echo "Maven build started"
    - echo "$TEST"
    - mvn verify

sonarqube-check:
  image: maven:3.6.3-jdk-11
  variables:
    SONAR_TOKEN: "hidden"
    SONAR_HOST_URL: "http://localhost:9000"
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script:
    - mvn verify sonar:sonar -Dsonar.qualitygate.wait=true
  allow_failure: true
  only:
    - merge_requests
    - master
    - develop

最佳答案

正确答案:

 -mvn clean install
 -mvn "-Dsonar.qualitygate=true" sonar:sonar

-Dsonar.qualitygate=true 应放在引号中并位于 mvn 之后。

显然这是 Windows shell 的一些问题。

关于spring - 未知生命周期阶段 ".qualitygate.wait=true",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64426026/

相关文章:

java - Camel : Route from direct to processor

java - 通过Java配置定义Spring RestController

maven - 如何将angular2与spring boot一起使用

kotlin - 尝试将 Jacoco 代码覆盖率导入 SonarQube 时出现问题 : Cannot import coverage information for file, 覆盖率数据无效

c# - 必须设置属性 "sonar.cs.fxcop.assembly"并且项目必须已经构建

java - Spring OAuth2 安全性和 ResourceServer 配置

java - Maven 对源项目的依赖(爆炸)

maven - 带有 JSF 的 Spring Boot;找不到工厂 javax.faces.context.FacesContextFactory 的备份

javascript - 定义一个常量而不是将这个文字复制 3 次 sonar

java - Spring禁用上下文:component-scan does not detect controllers