-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
241 lines (211 loc) · 6.82 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java Library project to get you started.
* For more details take a look at the Java Libraries chapter in the Gradle
* User Manual available at https://docs.gradle.org/5.6.1/userguide/java_library_plugin.html
*/
val artifactID: String = "utils"
val groupID: String = "io.github.kennedykori"
project.group = groupID
plugins {
// Apply the java-library plugin to add support for Java Library
`java-library`
// Apply the jacoco plugin to aid in test coverage
jacoco
// Apply the checkstyle plugin to perform quality checks on the project sources
checkstyle
// Apply the maven publish plugin
`maven-publish`
// Apply the signing plugin to digitally sign built files and artifacts.
signing
// Checker Framework pluggable type-checking.
// This MUST be applied after plugins that introduce Java compilation tasks,
// typically `java` or `java-library`.
alias(libs.plugins.checker.framework)
// Apply the gradle nexus plugin to automate publishing to any Nexus instance
// including Maven Central.
alias(libs.plugins.gradle.nexus.publish.plugin)
alias(libs.plugins.spotless)
}
checkstyle { toolVersion = libs.versions.checkstyle.get() }
apply(plugin = "org.checkerframework")
configure<org.checkerframework.gradle.plugin.CheckerFrameworkExtension> {
checkers =
listOf(
"org.checkerframework.checker.formatter.FormatterChecker",
"org.checkerframework.checker.index.IndexChecker",
"org.checkerframework.checker.nullness.NullnessChecker",
"org.checkerframework.common.value.ValueChecker",
"org.checkerframework.framework.util.PurityChecker",
)
extraJavacArgs =
listOf(
// "--module-path", configurations.compileOnly.get().asPath
// "-Werror",
"-AcheckPurityAnnotations",
"-ArequirePrefixInWarningSuppressions",
"-AshowPrefixInWarningMessages",
"-AsuggestPureMethods",
"-AwarnRedundantAnnotations",
"-AwarnUnneededSuppressions",
)
}
dependencies {
// Use JUnit test framework
testImplementation(libs.junit.jupiter)
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
// Apply a specific Java toolchain to ease working on different environments.
java {
toolchain { languageVersion.set(JavaLanguageVersion.of(11)) }
withJavadocJar()
withSourcesJar()
}
nexusPublishing {
repositories {
sonatype {
nexusUrl = uri("https://s01.oss.sonatype.org/service/local/")
snapshotRepositoryUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
}
}
publishing {
publications {
create<MavenPublication>("utils") {
this.artifactId = artifactID
this.groupId = groupID
this.version = project.version.toString()
from(components["java"])
pom {
name = "$groupID:$artifactID"
description =
"Collection of utility methods and classes for checking and " +
"validating primitives and objects in Java."
developers {
developer {
id = "kennedykori"
name = "Kennedy Kori"
email = "kennedykori47@gmail.com"
}
}
licenses {
license {
name = "MIT License"
url = "https://github.com/kennedykori/jutils/blob/master/LICENSE"
distribution = "repo"
}
}
packaging = "jar"
scm {
connection = "scm:git:git@github.com:kennedykori/jutils.git"
developerConnection = "scm:git:git@github.com:kennedykori/jutils.git"
url = "https://github.com/kennedykori/jutils"
}
url = "https://github.com/kennedykori/jutils"
}
versionMapping {
usage("java-api") { fromResolutionOf("runtimeClasspath") }
usage("java-runtime") { fromResolutionResult() }
}
}
}
repositories {
mavenLocal()
maven {
// Repo directory relative to the build directory.
val localRepoDir: String = project.providers.gradleProperty("repo.local").get()
name = "localReleases"
url = uri(layout.buildDirectory.dir(localRepoDir))
}
maven {
val gitHubRepoURL: String = project.providers.gradleProperty("repo.github").get()
name = "GitHubPackages"
url = uri(gitHubRepoURL)
credentials {
username =
project.providers
.gradleProperty("github.username")
.getOrElse(System.getenv("GITHUB_USERNAME"))
password =
project.providers
.gradleProperty("github.token")
.getOrElse(System.getenv("GITHUB_TOKEN"))
}
}
}
}
repositories { mavenCentral() }
signing {
val useInMemorySigning = project.providers.gradleProperty("signing.inMemory").getOrElse("false")
if (useInMemorySigning == "true") {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
}
sign(project.publishing.publications["utils"])
}
spotless {
format("misc") {
// define the files to apply `misc` to
target(".gitattributes", ".gitignore", "*.properties", ".toml")
// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces(4)
endWithNewline()
}
java {
// Rearrange imports using the default importOrder configuration.
importOrder()
// Remove unused imports. Use `cleanthat-javaparser-unnecessaryimport`
// which enables processing any language level source file with a JDK8+ Runtime.
removeUnusedImports("cleanthat-javaparser-unnecessaryimport")
// Refactor code
cleanthat()
// Format using google-java-format.
// https://github.com/google/google-java-format
googleJavaFormat()
// Fix formatting of type annotations.
// See https://github.com/diffplug/spotless/tree/main/plugin-gradle#formatannotations
formatAnnotations()
}
kotlinGradle {
target("*.gradle.kts")
ktlint()
ktfmt()
}
}
tasks.jacocoTestCoverageVerification {
dependsOn(tasks.jacocoTestReport)
violationRules { rule { limit { minimum = "1.0".toBigDecimal() } } }
}
tasks.jacocoTestReport {
dependsOn(tasks.test)
reports {
html.required = true
xml.required = true
}
}
tasks.jar {
manifest {
attributes(
mapOf(
"Automatic-Module-Name" to "$groupID.$artifactID",
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
),
)
}
}
tasks.test {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
testLogging { events("passed", "skipped", "failed") }
}
tasks.withType<Checkstyle>().configureEach {
configFile = configDirectory.get().file("google_checks.xml").asFile
reports {
html.required = true
xml.required = true
}
}