A quick update:
I have added the profiles from the guide in the pom.xml file and the profiles section looks like this:
<profiles>
<profile>
<id>coverage</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
I am running sonar:sonar
in my script section of gitlab-ci.yml file and my gitlab-ci.yml file looks like this:
image: maven:3-jdk-8
stages:
- build
- static-test
maven-build:
stage: build
script:
- mvn package
- mvn sonar:sonar
artifacts:
paths:
- target/surefire-reports/TEST-*.xml
- target/site/jacoco/jacoco.xml
reports:
junit:
- target/surefire-reports/TEST-*.xml
- target/site/jacoco/jacoco.xml
#===============Code Quality /Static Testing==========
sonarqube-pretest:
stage: static-test
#tags: [old-runner]
image: sonarsource/sonar-scanner-cli:latest
variables:
SONAR_TOKEN: "0239abe136224e84ea14d48201f0cb7bcd09edae"
SONAR_HOST_URL: "http://192.168.2.30:9000"
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
GIT_DEPTH: 1
script:
- pwd
cache:
key: ${CI_JOB_NAME}
paths:
- .sonar/cache
sonarqube-test:
stage: static-test
#tags: [old-runner]
image: sonarsource/sonar-scanner-cli:latest
variables:
SONAR_TOKEN: "0239abe136224e84ea14d48201f0cb7bcd09edae"
SONAR_HOST_URL: "http://192.168.2.30:9000"
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
GIT_DEPTH: 1
script:
- sonar-scanner -Dsonar.qualitygate.wait=true
allow_failure: true
Is this the right approach to follow?