Skip to content

Commit b75018b

Browse files
authored
Added sonar for gradle.
1 parent 6632c11 commit b75018b

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

.github/workflows/maven.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,30 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v2
19-
- name: Set up JDK 1.8
19+
- name: Set up JDK 11
2020
uses: actions/setup-java@v1
2121
with:
22-
java-version: 1.8
22+
java-version: 11
23+
- name: Cache SonarCloud packages
24+
uses: actions/cache@v1
25+
with:
26+
path: ~/.sonar/cache
27+
key: ${{ runner.os }}-sonar
28+
restore-keys: ${{ runner.os }}-sonar
2329
- uses: actions/cache@v1
2430
with:
2531
path: ~/.gradle/caches
2632
key: ${{ runner.os }}-gradle
2733
restore-keys: ${{ runner.os }}-gradle
2834
- name: Build with Gradle
29-
run: chmod +x gradlew && ./gradlew spotlessJavaCheck test
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
SONAR_TOKEN: f4f48f5dc3d59b444b238326cdf534ae5614cc59
38+
run: chmod +x gradlew && ./gradlew spotlessJavaCheck test jacocoTestReport sonarqube -Dsonar.projectKey=javadev_LeetCode-in-Java -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=javadev-github
39+
- uses: codecov/codecov-action@v1
40+
with:
41+
file: ./**/target/site/jacoco/jacoco.xml
42+
name: codecov
3043

3144
build-sonar:
3245
name: Build
@@ -39,24 +52,11 @@ jobs:
3952
uses: actions/setup-java@v1
4053
with:
4154
java-version: 11
42-
- name: Cache SonarCloud packages
43-
uses: actions/cache@v1
44-
with:
45-
path: ~/.sonar/cache
46-
key: ${{ runner.os }}-sonar
47-
restore-keys: ${{ runner.os }}-sonar
4855
- name: Cache Maven packages
4956
uses: actions/cache@v1
5057
with:
5158
path: ~/.m2
5259
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
5360
restore-keys: ${{ runner.os }}-m2
5461
- name: Build and analyze
55-
env:
56-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57-
SONAR_TOKEN: f4f48f5dc3d59b444b238326cdf534ae5614cc59
58-
run: mvn -B test jacoco:report org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.organization=javadev-github -Dsonar.host.url=https://sonarcloud.io -Dsonar.projectKey=javadev_LeetCode-in-Java
59-
- uses: codecov/codecov-action@v1
60-
with:
61-
file: ./**/target/site/jacoco/jacoco.xml
62-
name: codecov
62+
run: mvn -B compile

build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ plugins {
22
id 'java'
33
id 'maven-publish'
44
id 'com.diffplug.spotless' version '5.15.1'
5+
id 'org.sonarqube' version '3.0'
56
}
67

8+
apply plugin: 'jacoco'
9+
710
repositories {
811
mavenLocal()
912
mavenCentral()
@@ -58,3 +61,9 @@ spotless {
5861
endWithNewline()
5962
}
6063
}
64+
65+
jacocoTestReport {
66+
reports {
67+
xml.enabled true
68+
}
69+
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sonar.coverage.jacoco.xmlReportPaths=build/jacoco/test/jacocoTestReport.xml

0 commit comments

Comments
 (0)