-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
244 lines (211 loc) · 7.58 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
242
243
244
// Copyright 2019 Axel Howind
//
// 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 com.adarshr.gradle.testlogger.theme.ThemeType
import com.dua3.cabe.processor.Configuration
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.gradle.internal.extensions.stdlib.toDefaultLowerCase
import java.net.URI
plugins {
id("java-library")
id("jvm-test-suite")
id("maven-publish")
id("signing")
id("idea")
alias(libs.plugins.versions)
alias(libs.plugins.test.logger)
alias(libs.plugins.spotbugs)
alias(libs.plugins.cabe)
}
/////////////////////////////////////////////////////////////////////////////
object Meta {
const val GROUP = "com.dua3.meja"
const val SCM = "https://github.com/xzel23/meja.git"
const val REPO = "public"
const val LICENSE_NAME = "The Apache Software License, Version 2.0"
const val LICENSE_URL = "https://www.apache.org/licenses/LICENSE-2.0.txt"
const val DEVELOPER_ID = "axh"
const val DEVELOPER_NAME = "Axel Howind"
const val DEVELOPER_EMAIL = "[email protected]"
const val ORGANIZATION_NAME = "dua3"
const val ORGANIZATION_URL = "https://www.dua3.com"
}
/////////////////////////////////////////////////////////////////////////////
subprojects {
project.version = rootProject.libs.versions.projectVersion.get()
fun isDevelopmentVersion(versionString : String) : Boolean {
val v = versionString.toDefaultLowerCase()
val markers = listOf("snapshot", "alpha", "beta")
for (marker in markers) {
if (v.contains("-$marker") || v.contains(".$marker")) {
return true
}
}
return false
}
val isReleaseVersion = !isDevelopmentVersion(project.version.toString())
val isSnapshot = project.version.toString().toDefaultLowerCase().contains("snapshot")
apply(plugin = "java-library")
apply(plugin = "jvm-test-suite")
apply(plugin = "maven-publish")
apply(plugin = "signing")
apply(plugin = "idea")
apply(plugin = "com.github.ben-manes.versions")
apply(plugin = "com.adarshr.test-logger")
apply(plugin = "com.github.spotbugs")
apply(plugin = "com.dua3.cabe")
java {
withJavadocJar()
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.add("-Xlint:-module")
}
cabe {
if (isReleaseVersion) {
config.set(Configuration.parse("publicApi=THROW_IAE:privateApi=ASSERT"))
} else {
config.set(Configuration.DEVELOPMENT)
}
}
// dependencies
dependencies {
// Cabe (source annotations)
implementation(rootProject.libs.jspecify)
// LOG4J
implementation(platform(rootProject.libs.log4j.bom))
implementation(rootProject.libs.log4j.api)
}
idea {
module {
inheritOutputDirs = false
outputDir = project.layout.buildDirectory.file("classes/java/main/").get().asFile
testOutputDir = project.layout.buildDirectory.file("classes/java/test/").get().asFile
}
}
testing {
suites {
val test by getting(JvmTestSuite::class) {
useJUnitJupiter()
dependencies {
implementation(rootProject.libs.log4j.core)
}
}
}
}
testlogger {
theme = ThemeType.STANDARD
}
tasks.compileJava {
options.encoding = "UTF-8"
}
tasks.compileTestJava {
options.encoding = "UTF-8"
}
tasks.javadoc {
options.encoding = "UTF-8"
}
// === publication: MAVEN = == >
// Create the publication with the pom configuration:
publishing {
publications {
create<MavenPublication>("maven") {
groupId = Meta.GROUP
artifactId = project.name
version = project.version.toString()
from(components["java"])
pom {
withXml {
val root = asNode()
root.appendNode("description", project.description)
root.appendNode("name", project.name)
root.appendNode("url", Meta.SCM)
}
licenses {
license {
name.set(Meta.LICENSE_NAME)
url.set(Meta.LICENSE_URL)
}
}
developers {
developer {
id.set(Meta.DEVELOPER_ID)
name.set(Meta.DEVELOPER_NAME)
email.set(Meta.DEVELOPER_EMAIL)
organization.set(Meta.ORGANIZATION_NAME)
organizationUrl.set(Meta.ORGANIZATION_URL)
}
}
scm {
url.set(Meta.SCM)
}
}
}
}
repositories {
// Sonatype OSSRH
maven {
val releaseRepo = URI("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
val snapshotRepo = URI("https://s01.oss.sonatype.org/content/repositories/snapshots/")
url = if (isSnapshot) snapshotRepo else releaseRepo
credentials {
username = project.properties["ossrhUsername"].toString()
password = project.properties["ossrhPassword"].toString()
}
}
}
}
// === sign artifacts
signing {
isRequired = isReleaseVersion && gradle.taskGraph.hasTask("publish")
sign(publishing.publications["maven"])
}
// === SPOTBUGS ===
spotbugs.excludeFilter.set(rootProject.file("spotbugs-exclude.xml"))
tasks.withType<com.github.spotbugs.snom.SpotBugsTask> {
reports.create("html") {
required.set(true)
outputLocation = project.layout.buildDirectory.file("reports/spotbugs.html").get().asFile
setStylesheet("fancy-hist.xsl")
}
}
// === PUBLISHING ===
tasks.withType<PublishToMavenRepository> {
dependsOn(tasks.publishToMavenLocal)
}
tasks.withType<Jar> {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
}
allprojects {
// versions plugin configuration
fun isStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "[0-9,.v-]+-(rc|alpha|beta|b)(-?[0-9]*)?".toRegex()
val isStable = stableKeyword || !regex.matches(version)
return isStable
}
tasks.withType<DependencyUpdatesTask> {
resolutionStrategy {
componentSelection {
all {
if (!isStable(candidate.version)) {
reject("Release candidate")
}
}
}
}
}
}