/
build.gradle.kts
264 lines (244 loc) · 10.5 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import com.github.vlsi.gradle.properties.dsl.props
import java.util.Locale
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
plugins {
id("com.github.autostyle")
id("com.gradle.plugin-publish") apply false
id("com.github.vlsi.gradle-extensions")
id("com.github.vlsi.ide")
id("com.github.vlsi.stage-vote-release")
kotlin("jvm") apply false
}
val String.v: String get() = rootProject.extra["$this.version"] as String
val buildVersion = "autostyle".v + releaseParams.snapshotSuffix
println("Building Autostyle $buildVersion")
val enableGradleMetadata by props()
val autostyleSelf by props()
val skipAutostyle by props()
val skipJavadoc by props()
releaseParams {
tlp.set("Autostyle")
organizationName.set("autostyle")
componentName.set("Autostyle")
prefixForProperties.set("gh")
svnDistEnabled.set(false)
sitePreviewEnabled.set(false)
nexus {
mavenCentral()
}
voteText.set {
"""
${it.componentName} v${it.version}-rc${it.rc} is ready for preview.
Git SHA: ${it.gitSha}
Staging repository: ${it.nexusRepositoryUri}
""".trimIndent()
}
}
allprojects {
group = "com.github.autostyle"
version = buildVersion
val javaUsed = file("src/main/java").isDirectory || file("src/test/java").isDirectory
val kotlinUsed = file("src/main/kotlin").isDirectory || file("src/test/kotlin").isDirectory
if (javaUsed) {
apply(plugin = "java-library")
apply(plugin = "mdoclet")
dependencies {
val compileOnly by configurations
compileOnly("com.github.spotbugs:spotbugs-annotations:4.8.4")
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
}
}
if (kotlinUsed) {
apply(plugin = "java-library")
apply(plugin = "org.jetbrains.kotlin.jvm")
dependencies {
val implementation by configurations
implementation(kotlin("stdlib"))
}
}
if (javaUsed || kotlinUsed) {
dependencies {
val implementation by configurations
implementation(platform(project(":autostyle-bom")))
}
}
val hasTests = file("src/test/java").isDirectory || file("src/test/kotlin").isDirectory
if (hasTests) {
// Add default tests dependencies
dependencies {
val testImplementation by configurations
val testRuntimeOnly by configurations
testImplementation(platform(project(":autostyle-bom-testing")))
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testImplementation("org.hamcrest:hamcrest")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
}
tasks.withType<AbstractArchiveTask>().configureEach {
// Ensure builds are reproducible
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
dirMode = "775".toInt(8)
fileMode = "664".toInt(8)
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
apiVersion = "1.4"
jvmTarget = "1.8"
freeCompilerArgs += "-Xjvm-default=all"
freeCompilerArgs += "-Xjdk-release=1.8"
}
}
if (!skipAutostyle) {
if (!autostyleSelf) {
apply(plugin = "com.github.autostyle")
}
// Autostyle is already published, so we can always use it, except it is broken :)
// So there's an option to disable it
apply(from = "$rootDir/autostyle.gradle.kts")
}
plugins.withType<JavaPlugin> {
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
withSourcesJar()
if (!skipJavadoc) {
withJavadocJar()
}
}
repositories {
mavenCentral()
}
apply(plugin = "maven-publish")
if (!enableGradleMetadata) {
tasks.withType<GenerateModuleMetadata> {
enabled = false
}
}
tasks {
withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release.set(8)
}
withType<Jar>().configureEach {
manifest {
attributes["Bundle-License"] = "Apache-2.0"
attributes["Implementation-Title"] = "Autostyle"
attributes["Implementation-Version"] = project.version
attributes["Specification-Vendor"] = "Autostyle"
attributes["Specification-Version"] = project.version
attributes["Specification-Title"] = "Autostyle"
attributes["Implementation-Vendor"] = "Autostyle"
attributes["Implementation-Vendor-Id"] = "com.github.vlsi.autostyle"
}
}
withType<Test>().configureEach {
useJUnitPlatform()
testLogging {
exceptionFormat = TestExceptionFormat.FULL
showStandardStreams = true
}
// Pass the property to tests
fun passProperty(name: String, default: String? = null) {
val value = System.getProperty(name) ?: default
value?.let { systemProperty(name, it) }
}
passProperty("junit.jupiter.execution.parallel.enabled", "true")
passProperty("junit.jupiter.execution.parallel.mode.default", "concurrent")
passProperty("junit.jupiter.execution.timeout.default", "5 m")
}
configure<PublishingExtension> {
if (project.path == ":") {
// Do not publish "root" project. Java plugin is applied here for DSL purposes only
return@configure
}
publications {
if (project.path != ":autostyle-plugin-gradle") {
create<MavenPublication>(project.name) {
artifactId = project.name
version = rootProject.version.toString()
description = project.description
from(project.components.get("java"))
}
}
withType<MavenPublication> {
// if (!skipJavadoc) {
// Eager task creation is required due to
// https://github.com/gradle/gradle/issues/6246
// artifact(sourcesJar.get())
// artifact(javadocJar.get())
// }
// Use the resolved versions in pom.xml
// Gradle might have different resolution rules, so we set the versions
// that were used in Gradle build/test.
versionMapping {
usage(Usage.JAVA_RUNTIME) {
fromResolutionResult()
}
usage(Usage.JAVA_API) {
fromResolutionOf("runtimeClasspath")
}
}
pom {
withXml {
val sb = asString()
var s = sb.toString()
// <scope>compile</scope> is Maven default, so delete it
s = s.replace("<scope>compile</scope>", "")
// Cut <dependencyManagement> because all dependencies have the resolved versions
s = s.replace(
Regex(
"<dependencyManagement>.*?</dependencyManagement>",
RegexOption.DOT_MATCHES_ALL
),
""
)
sb.setLength(0)
sb.append(s)
// Re-format the XML
asNode()
}
name.set(
(project.findProperty("artifact.name") as? String)
?: "Autostyle ${project.name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}"
)
description.set(
project.description
?: "Autostyle ${project.name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}"
)
developers {
developer {
id.set("vlsi")
name.set("Vladimir Sitnikov")
email.set("sitnikov.vladimir@gmail.com")
}
}
inceptionYear.set("2019")
url.set("https://github.com/autostyle/autostyle")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
comments.set("A business-friendly OSS license")
distribution.set("repo")
}
}
issueManagement {
system.set("GitHub")
url.set("https://github.com/autostyle/autostyle/issues")
}
scm {
connection.set("scm:git:https://github.com/autostyle/autostyle.git")
developerConnection.set("scm:git:https://github.com/autostyle/autostyle.git")
url.set("https://github.com/autostyle/autostyle")
tag.set("HEAD")
}
}
}
}
}
}
}
}