-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
171 lines (143 loc) · 4.8 KB
/
build.gradle.kts
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* Juggle -- a declarative search tool for Java
*
* Copyright 2020,2024 Paul Bennett
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
plugins {
application
jacoco
antlr
}
val friendlyName = "Juggle"
group = "com.angellane"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
antlr("org.antlr", "antlr4", "4.12.0")
implementation("org.antlr", "antlr4-runtime", "4.12.0")
implementation("info.picocli", "picocli", "4.7.2")
testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.9.2")
testImplementation("org.junit.jupiter", "junit-jupiter-engine", "5.9.2")
}
java.toolchain {
// We use a lot of Java 17 features: records, pattern matching, etc.
languageVersion.set(JavaLanguageVersion.of(17))
}
application {
mainClass.set("com.angellane.juggle.Main")
}
afterEvaluate {
tasks.withType<JavaCompile> {
options.compilerArgs.add("-Xlint:unchecked")
options.compilerArgs.add("-Xlint:deprecation")
options.compilerArgs.add("-parameters")
}
}
tasks.generateGrammarSource {
arguments = arguments + listOf("-package", "com.angellane.juggle.parser")
}
tasks.jar {
manifest {
attributes["Main-Class"] = application.mainClass
attributes["Implementation-Title"] = friendlyName
attributes["Implementation-Version"] = version
}
val dependencies = configurations
.runtimeClasspath
.get()
.map(::zipTree)
from(dependencies)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.named<Test>("test") {
useJUnitPlatform()
dependsOn(tasks.jar) // One of the tests in README.md uses the built JAR file
}
tasks.test {
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
}
tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
}
tasks.jacocoTestCoverageVerification {
dependsOn(tasks.jacocoTestReport)
violationRules {
rule {
limit {
minimum = "0.9".toBigDecimal()
}
}
}
}
// These next two blocks exclude our ANTLR-generated code from the JaCoCo
// report and verification steps. It's unclear to me why I can't put this
// code in the previous named tasks, but it works here.
tasks.withType<JacocoReport> {
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.map {
fileTree(it).apply {
exclude("com/angellane/juggle/parser/**")
}
}))
}
}
tasks.withType<JacocoCoverageVerification> {
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.map {
fileTree(it).apply {
exclude("com/angellane/juggle/parser/**")
}
}))
}
}
tasks.check {
dependsOn(tasks.jacocoTestCoverageVerification)
}
// This next section configures a couple of tasks to generate JAR files that are used as input to some
// of the tests. There's no need to invoke the tasks explicitly -- we hook them into test task too.
//
// This still feels a bit more complex than I'd have expected. Is there a better way?
var testLib = "testLib"
var testApp = "testApp"
var testLibSrc: SourceSet = sourceSets.create(testLib)
var testAppSrc: SourceSet = sourceSets.create(testApp)
var jarTestLibTaskName = "jar${testLib.uppercaseFirstChar()}"
var jarTestAppTaskName = "jar${testApp.uppercaseFirstChar()}"
tasks.named<JavaCompile>(testAppSrc.compileJavaTaskName) {
dependsOn(tasks[testLibSrc.compileJavaTaskName])
classpath = testLibSrc.runtimeClasspath
}
tasks.create<Jar>(jarTestLibTaskName) {
group = "build"
description = "Assembles a jar archive containing the $testLib classes"
dependsOn(tasks[testLibSrc.compileJavaTaskName])
from(tasks[testLibSrc.compileJavaTaskName].outputs)
archiveBaseName.set(testLib)
archiveVersion.set("")
}
tasks.create<Jar>(jarTestAppTaskName) {
group = "build"
description = "Assembles a jar archive containing the $testApp classes"
dependsOn(tasks[testAppSrc.compileJavaTaskName])
from(tasks[testAppSrc.compileJavaTaskName].outputs)
archiveBaseName.set(testApp)
archiveVersion.set("")
}
tasks.named("test") {
dependsOn(jarTestLibTaskName, jarTestAppTaskName)
}