-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.gradle
128 lines (108 loc) · 3.41 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* This file contains the Gradle setup for a simple Java application project.
*
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/7.3/userguide/building_java_projects.html
*/
plugins {
// Apply the application plugin to add support for building a CLI application.
id 'application'
// Apply the java plugin to add support for Java.
id 'java'
// Apply the Jacoco plugin to add suppport for JUnit test coverage reports.
id 'jacoco'
}
// In this section you declare where to find the dependencies of your project.
repositories {
// Use Maven Central for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
dependencies {
// JUnit Jupiter API for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.0'
// JUnit Jupiter Engine for testing.
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
// JUnit Platform Launcher for testing.
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
application {
// Define the main class for the application.
mainClass.set('hellos.Main')
}
test {
// Use junit platform for unit tests.
useJUnitPlatform()
// After running the tests, generate a coverage report
finalizedBy jacocoTestReport
// After running the tests, check the coverage level
finalizedBy jacocoTestCoverageVerification
}
jacocoTestReport {
// Running the test report task automatically runs test first
dependsOn test
reports {
// This isn't strictly necessary, but the default reports
// location is buried pretty deep in the build directory,
// so this makes it easier to find.
html.outputLocation = file("${buildDir}/jacocoHtml")
}
afterEvaluate {
// This excludes the `Main` class from coverage verification.
// All the "useful" logic is in the `Hellos` class, so we'll
// check the coverage on that class instead.
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['**/Main.class'])
}))
}
}
jacocoTestCoverageVerification {
// Running the test verification task automatically runs test first
dependsOn test
// These are the rules applied to the test coverage
violationRules {
rule {
// We are looking at the entire bundle overall, i.e.,
// 80% of all instructions across all the Java files
// need to be covered.
element = 'BUNDLE'
// 80% of instructions should be covered
limit {
counter = 'INSTRUCTION'
minimum = 0.8
}
// 80% of lines should be covered
limit {
counter = 'LINE'
minimum = 0.8
}
// 80% of branches should be covered
limit {
counter = 'BRANCH'
minimum = 0.8
}
// 80% of methods should be covered
limit {
counter = 'METHOD'
minimum = 0.8
}
}
}
// This excludes the `Main` class from coverage verification.
// All the "useful" logic is in the `Hellos` class, so we'll
// check the coverage on that class instead.
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['**/Main.class'])
}))
}
}
tasks.withType(JavaCompile) {
// All of our source files are written in UTF-8.
options.encoding = 'UTF-8'
}