forked from tginsberg/gatherers4j
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
168 lines (153 loc) · 5.22 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
import net.ltgt.gradle.errorprone.CheckSeverity
import net.ltgt.gradle.errorprone.errorprone
import java.io.IOException
import java.net.URI
plugins {
id("com.adarshr.test-logger") version "4.0.0"
id("jacoco")
id("java-library")
id("maven-publish")
id("net.ltgt.errorprone") version "4.1.0"
id("signing")
}
description = "An extra set of helpful Stream Gatherers for Java"
group = "com.ginsberg"
version = file("VERSION.txt").readLines().first()
@Suppress("PropertyName")
val ENABLE_PREVIEW = "--enable-preview"
val gitBranch = gitBranch()
val gatherers4jVersion = if(gitBranch == "main" || gitBranch.startsWith("release/")) version.toString()
else "${gitBranch.substringAfterLast("/")}-SNAPSHOT"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(23)
}
withJavadocJar()
withSourcesJar()
}
repositories {
mavenCentral()
}
dependencies {
api("org.jspecify:jspecify:1.0.0") {
because("Annotating with JSpecify makes static analysis more accurate")
}
testRuntimeOnly("org.junit.platform:junit-platform-launcher") {
because("Starting in Gradle 9.0, this needs to be an explicitly declared dependency")
}
testImplementation("org.junit.jupiter:junit-jupiter:5.11.2")
testImplementation("org.assertj:assertj-core:3.26.3") {
because("These assertions are clearer than JUnit+Hamcrest")
}
errorprone("com.google.errorprone:error_prone_core:2.36.0")
errorprone("com.uber.nullaway:nullaway:0.12.1")
}
publishing {
publications {
create<MavenPublication>("gatherers4j") {
from(components["java"])
pom {
name = "Gatherers4J"
description = project.description
version = gatherers4jVersion
url = "https://github.com/tginsberg/gatherers4j"
organization {
name = "com.ginsberg"
url = "https://github.com/tginsberg"
}
issueManagement {
system = "GitHub"
url = "https://github.com/tginsberg/gatherers4j/issues"
}
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
developers {
developer {
id = "tginsberg"
name = "Todd Ginsberg"
email = "[email protected]"
}
}
scm {
connection = "scm:git:https://github.com/tginsberg/gatherers4j.git"
developerConnection = "scm:git:https://github.com/tginsberg/gatherers4j.git"
url = "https://github.com/tginsberg/gatherers4j"
}
}
}
}
repositories {
maven {
url = if(version.toString().endsWith("-SNAPSHOT")) URI("https://oss.sonatype.org/content/repositories/snapshots/")
else URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = System.getenv("SONATYPE_USERNAME")
password = System.getenv("SONATYPE_TOKEN")
}
}
}
}
signing {
useInMemoryPgpKeys(System.getenv("SONATYPE_SIGNING_KEY"), System.getenv("SONATYPE_SIGNING_PASSPHRASE"))
sign(publishing.publications["gatherers4j"])
}
tasks {
withType<JavaCompile> {
options.compilerArgs.add(ENABLE_PREVIEW)
options.errorprone {
check("NullAway", CheckSeverity.ERROR)
option("NullAway:AnnotatedPackages", "com.ginsberg.gatherers4j")
}
if (name.lowercase().contains("test")) {
options.errorprone {
disable("NullAway")
}
}
}
jacocoTestReport {
dependsOn(test)
reports {
xml.required = true
}
}
jar {
manifest {
attributes(
"Implementation-Title" to "Gatherers4J",
"Implementation-Version" to archiveVersion
)
}
}
javadoc {
(options as CoreJavadocOptions).apply {
addStringOption("source", rootProject.java.toolchain.languageVersion.get().toString())
addBooleanOption("-enable-preview", true)
addStringOption("Xdoclint:none", "-quiet") // TODO: Remove this when we've documented things
}
}
publish {
doLast {
println("Project Version: $version")
println("Publish Version: $gatherers4jVersion")
}
}
test {
finalizedBy(jacocoTestReport)
jvmArgs(ENABLE_PREVIEW)
useJUnitPlatform()
}
}
fun gitBranch(): String =
ProcessBuilder("git rev-parse --abbrev-ref HEAD".split(" "))
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
.run {
val error = errorStream.bufferedReader().readText()
if (error.isNotEmpty()) throw IOException(error)
inputStream.bufferedReader().readText().trim()
}