docker network create ap_net
version: "3"
name: sonarqube
services:
sonarqube:
image: sonarqube:8.9.10-community
volumes:
- "/home/ted/project/sonarqube:/opt/sonarqube/data"
ports:
- 9000:9000
networks:
- ap_net
networks:
ap_net:
external: true
docker-compose -f docker-compose-sonarqube.yaml up
這邊注意一下,一定要先下clean package才可以用sonarqube掃描
不然會有以下錯誤
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.10.0.2594:sonar (default-cli) on project xxxxxx: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property. -> [Help 1]
version: "3"
name: xxxx-maven
services:
maven:
image: maven:3.9.4-eclipse-temurin-8-alpine
volumes:
- "/home/ted/project/xxxx/source:/usr/src/mymaven"
- "/home/ted/project/xxxx/m2:/root/.m2"
working_dir: /usr/src/mymaven
command: mvn clean package sonar:sonar -Dsonar.projectKey=xxxx -Dsonar.host.url=http://sonarqube:9000 -Dsonar.login=18d51ae8cc1c44ab9e1c1d041636be4ff857f25d
networks:
- ap_net
networks:
ap_net:
external: true
docker-compose -f docker-compose-build.yaml up
結束後,就可以取得sonarqube報告,跟war檔案。