Repository navigation
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
195 lines (177 loc) · 6.31 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
195 lines (177 loc) · 6.31 KB
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
import org.jreleaser.model.Active
plugins {
id("java-library")
id("checkstyle")
id("maven-publish")
alias(libs.plugins.jreleaser)
}
group = "org.komamitsu"
version = "3.0.0"
description = "Jackson 3.x extension that adds support for MessagePack"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
withJavadocJar()
withSourcesJar()
}
repositories {
mavenCentral()
}
dependencies {
api(libs.jackson.databind)
testImplementation(libs.msgpack.core)
testImplementation(libs.junit.jupiter)
testImplementation(libs.hamcrest)
testImplementation(libs.commons.math3)
testRuntimeOnly(libs.junit.platform.launcher)
}
// PackageVersion.java carries the coordinates and version Jackson reports via Versioned.
// Generate it from the Gradle project so it cannot drift from the published POM.
val packageDir = "org/komamitsu/jackson/dataformat/msgpack"
val generatePackageVersion = tasks.register("generatePackageVersion") {
val outputDir = layout.buildDirectory.dir("generated/sources/packageVersion/java/main")
val projectVersion = project.version.toString()
val projectGroup = project.group.toString()
val projectName = project.name
inputs.property("version", projectVersion)
outputs.dir(outputDir)
doLast {
val (major, minor, patch, snapshot) = Regex("""(\d+)\.(\d+)\.(\d+)(?:-(.+))?""")
.matchEntire(projectVersion)!!.destructured
val snapshotInfo = if (snapshot.isEmpty()) "null" else "\"$snapshot\""
val file = outputDir.get().file("$packageDir/PackageVersion.java").asFile
file.parentFile.mkdirs()
file.writeText(
"""
|package ${packageDir.replace('/', '.')};
|
|import tools.jackson.core.Version;
|import tools.jackson.core.Versioned;
|
|// Generated by the Gradle build from the project version. Do not edit.
|public class PackageVersion
| implements Versioned
|{
| public static final Version VERSION = new Version($major, $minor, $patch, $snapshotInfo, "$projectGroup", "$projectName");
|
| @Override
| public Version version()
| {
| return VERSION;
| }
|}
|""".trimMargin()
)
}
}
sourceSets.main {
java.srcDir(generatePackageVersion)
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation"))
}
tasks.withType<Javadoc>().configureEach {
(options as StandardJavadocDocletOptions).addBooleanOption("Xdoclint:none", true)
}
// Compilation is pinned to 17 above; tests can run on a newer JDK with -PtestJavaVersion=21.
val testJavaVersion = providers.gradleProperty("testJavaVersion").map(JavaLanguageVersion::of)
tasks.test {
useJUnitPlatform {
excludeTags("soak")
}
// A non-UTF-8 default charset, so that any conversion that forgets to name a charset
// corrupts non-ASCII text in the tests instead of only on users' Windows machines.
jvmArgs("-ea", "-Dfile.encoding=windows-1252")
if (testJavaVersion.isPresent) {
javaLauncher = javaToolchains.launcherFor { languageVersion = testJavaVersion }
}
testLogging {
events("failed")
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
// Long-running checks that the normal build skips. ./gradlew soakTest -Psoak.seconds=120
tasks.register<Test>("soakTest") {
group = "verification"
description = "Runs the soak tests (memory growth under sustained load)."
testClassesDirs = sourceSets["test"].output.classesDirs
classpath = sourceSets["test"].runtimeClasspath
useJUnitPlatform {
includeTags("soak")
}
val soakSeconds = providers.gradleProperty("soak.seconds").orElse("30")
jvmArgs("-ea", "-Xmx256m", "-Dsoak.seconds=${soakSeconds.get()}")
if (testJavaVersion.isPresent) {
javaLauncher = javaToolchains.launcherFor { languageVersion = testJavaVersion }
}
testLogging {
events("passed", "failed")
showStandardStreams = true
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
outputs.upToDateWhen { false }
}
checkstyle {
toolVersion = "10.21.1"
configFile = file("config/checkstyle/checkstyle.xml")
maxWarnings = 0
}
// Publications are staged locally; JReleaser signs them and uploads them to the Central Portal.
val stagingDir = layout.buildDirectory.dir("staging-deploy")
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
pom {
name = project.name
description = project.description
url = "https://github.com/komamitsu/jackson-dataformat-msgpack"
licenses {
license {
name = "Apache-2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
developers {
developer {
id = "komamitsu"
name = "Mitsunori Komatsu"
email = "komamitsu@gmail.com"
url = "https://github.com/komamitsu"
}
}
scm {
url = "https://github.com/komamitsu/jackson-dataformat-msgpack"
connection = "scm:git:git://github.com/komamitsu/jackson-dataformat-msgpack.git"
developerConnection = "scm:git:ssh://git@github.com/komamitsu/jackson-dataformat-msgpack.git"
}
}
}
}
repositories {
maven {
name = "staging"
url = uri(stagingDir)
}
}
}
jreleaser {
signing {
pgp {
active = Active.ALWAYS
armored = true
}
}
deploy {
maven {
mavenCentral.create("sonatype") {
active = Active.ALWAYS
url = "https://central.sonatype.com/api/v1/publisher"
applyMavenCentralRules = true
stagingRepository(stagingDir.get().asFile.path)
}
}
}
}