-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
193 lines (182 loc) · 6.6 KB
/
build.gradle.kts
File metadata and controls
193 lines (182 loc) · 6.6 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
///////////////////////////////////////////////////////////////////////////////
// GRADLE CONFIGURATION
///////////////////////////////////////////////////////////////////////////////
plugins {
java
`maven-publish`
signing
id("com.diffplug.spotless") version "6.25.0"
}
///////////////////////////////////////////////////////////////////////////////
// APP CONFIGURATION
///////////////////////////////////////////////////////////////////////////////
dependencies {
testImplementation(platform("org.junit:junit-bom:5.12.2"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation("org.assertj:assertj-core:3.25.3")
}
///////////////////////////////////////////////////////////////////////////////
// STANDARD CONFIGURATION FOR JAVA PROJECTS
///////////////////////////////////////////////////////////////////////////////
if (project.hasProperty("releaseTag")) {
project.version = project.property("releaseTag") as String
println("Release mode: version set to ${project.version}")
} else {
println("Development mode: version is ${project.version}")
}
val javaSourceLevel: String by project
val javaTargetLevel: String by project
java {
sourceCompatibility = JavaVersion.toVersion(javaSourceLevel)
targetCompatibility = JavaVersion.toVersion(javaTargetLevel)
println("Compiling Java $sourceCompatibility to Java $targetCompatibility.")
withJavadocJar()
withSourcesJar()
}
fun copyLicenseFiles() {
val metaInfDir = File(layout.buildDirectory.get().asFile, "resources/main/META-INF")
val licenseFile = File(project.rootDir, "LICENSE")
val noticeFile = File(project.rootDir, "NOTICE.md")
metaInfDir.mkdirs()
licenseFile.copyTo(File(metaInfDir, "LICENSE"), overwrite = true)
noticeFile.copyTo(File(metaInfDir, "NOTICE.md"), overwrite = true)
}
tasks {
spotless {
java {
target("src/**/*.java")
licenseHeaderFile("${project.rootDir}/LICENSE_HEADER")
importOrder("java", "javax", "org", "com", "")
removeUnusedImports()
googleJavaFormat()
}
kotlinGradle {
target("**/*.kts")
ktfmt()
}
}
test {
useJUnitPlatform()
testLogging { events("passed", "skipped", "failed") }
}
javadoc {
dependsOn(processResources)
val javadocLogo = project.findProperty("javadoc.logo") as String
val javadocCopyright = project.findProperty("javadoc.copyright") as String
val titleProperty = project.findProperty("title") as String
(options as StandardJavadocDocletOptions).apply {
overview = "src/main/javadoc/overview.html"
windowTitle = "$titleProperty - ${project.version}"
header(
"<div style=\"margin-top: 7px\">$javadocLogo $titleProperty - ${project.version}</div>")
docTitle("$titleProperty - ${project.version}")
use(true)
bottom(javadocCopyright)
encoding = "UTF-8"
charSet = "UTF-8"
if (JavaVersion.current().isJava11Compatible) {
addBooleanOption("html5", true)
addStringOption("Xdoclint:none", "-quiet")
}
}
doFirst { println("Generating Javadoc for ${project.name} version ${project.version}") }
}
jar {
dependsOn(processResources)
doFirst { copyLicenseFiles() }
manifest {
attributes(
mapOf(
"Implementation-Title" to (project.findProperty("title") as String),
"Implementation-Version" to project.version,
"Implementation-Vendor" to (project.findProperty("organization.name") as String),
"Implementation-URL" to (project.findProperty("project.url") as String),
"Specification-Title" to (project.findProperty("title") as String),
"Specification-Version" to project.version,
"Specification-Vendor" to (project.findProperty("organization.name") as String),
"Created-By" to
"${System.getProperty("java.version")} (${System.getProperty("java.vendor")})",
"Build-Jdk" to System.getProperty("java.version")))
}
}
named<Jar>("sourcesJar") {
doFirst { copyLicenseFiles() }
manifest {
attributes(
mapOf(
"Implementation-Title" to "${project.findProperty("title") as String} Sources",
"Implementation-Version" to project.version))
}
}
named<Jar>("javadocJar") {
dependsOn(javadoc)
doFirst { copyLicenseFiles() }
manifest {
attributes(
mapOf(
"Implementation-Title" to "${project.findProperty("title") as String} Documentation",
"Implementation-Version" to project.version))
}
}
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
pom {
name.set(project.findProperty("title") as String)
description.set(project.findProperty("description") as String)
url.set(project.findProperty("project.url") as String)
licenses {
license {
name.set(project.findProperty("license.name") as String)
url.set(project.findProperty("license.url") as String)
distribution.set(project.findProperty("license.distribution") as String)
}
}
developers {
developer {
name.set(project.findProperty("developer.name") as String)
email.set(project.findProperty("developer.email") as String)
}
}
organization {
name.set(project.findProperty("organization.name") as String)
url.set(project.findProperty("organization.url") as String)
}
scm {
connection.set(project.findProperty("scm.connection") as String)
developerConnection.set(project.findProperty("scm.developerConnection") as String)
url.set(project.findProperty("scm.url") as String)
}
ciManagement {
system.set(project.findProperty("ci.system") as String)
url.set(project.findProperty("ci.url") as String)
}
properties.set(
mapOf(
"project.build.sourceEncoding" to "UTF-8",
"maven.compiler.source" to javaSourceLevel,
"maven.compiler.target" to javaTargetLevel))
}
}
}
repositories {
maven {
if (project.hasProperty("sonatypeURL")) {
url = uri(project.property("sonatypeURL") as String)
credentials {
username = project.property("sonatypeUsername") as String
password = project.property("sonatypePassword") as String
}
}
}
}
}
signing {
if (project.hasProperty("releaseTag")) {
useGpgCmd()
sign(publishing.publications["mavenJava"])
}
}