-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.gradle.kts
292 lines (257 loc) · 9.77 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
import com.github.jengelman.gradle.plugins.shadow.ShadowExtension
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.konan.properties.loadProperties
import plugin.GenerateConstantsTask
plugins {
wrapper
idea
// `maven-publish`
`project-report`
kotlin("jvm")
kotlin("plugin.scripting") apply false
kotlin("plugin.serialization") apply false
id("moe.nikky.plugin.constants") apply false
id("com.github.johnrengelman.shadow") apply false
// id("org.jmailen.kotlinter") apply false
id("com.vanniktech.dependency.graph.generator")
}
println(
"""
*******************************************
You are building Voodoo Toolset !
Output files will be in [subproject]/build/libs
*******************************************
""".trimIndent()
)
object Maven {
val shadowClassifier = "all"
}
// specify version as -Pversion=x.y.z in gradle invocation
val releaseVersion = (properties["version"] as String?)?.takeUnless { it == "unspecified" }
val defaultVersion = "0.6.0"
val isCI = System.getenv("CI") != null
val versionSuffix = when {
isCI -> System.getenv("GITHUB_RUN_NUMBER")
else -> "local"
}
val fullVersion = "${releaseVersion ?: defaultVersion}-$versionSuffix" // TODO: just use -SNAPSHOT always ?
group = "moe.nikky.voodoo"
version = fullVersion
task<DefaultTask>("exportVersion") {
group = "help"
description = "exports $version to version.txt"
doLast {
logger.lifecycle("exporting version $version")
rootDir.resolve("version.txt").writeText(version.toString())
}
}
allprojects {
repositories {
mavenCentral()
maven("https://jitpack.io") {
name = "jitpack"
}
// mavenLocal()
}
task<DefaultTask>("depsize") {
group = "help"
description = "prints dependency sizes"
doLast {
val formatStr = "%,10.2f"
val files = configurations.default.get().resolve()
val size = files.map { it.length() / (1024.0 * 1024.0) }.sum()
val width = (files.map { it.name.length }.max() ?: 45) + 2
val out = buildString {
append("Total dependencies size:".padEnd(width))
append("${String.format(formatStr, size)} Mb\n\n".padStart(12))
configurations
.default
.get()
.resolve()
.sortedWith(compareBy { -it.length() })
.forEach {
append(it.name.padEnd(width))
append("${String.format(formatStr, (it.length() / 1024.0))} kb\n".padStart(12))
}
}
println(out)
}
}
}
subprojects {
group = rootProject.group
version = rootProject.version
apply {
plugin("idea")
// plugin("org.jmailen.kotlinter")
// plugin("io.gitlab.arturbosch.detekt")
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
tasks.withType<KotlinCompile> {
kotlinOptions {
apiVersion = "1.4"
languageVersion = "1.4"
jvmTarget = "1.8"
freeCompilerArgs += listOf(
// "-XXLanguage:+InlineClasses",
// "-progressive"
)
// useIR = true
}
}
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
base {
archivesBaseName = name.toLowerCase()
}
val jar by tasks.getting(Jar::class) {
archiveVersion.set("")
}
apply(plugin = "moe.nikky.plugin.constants")
val folder = listOf("voodoo") + project.name.split('-')
afterEvaluate {
val versionsProps = loadProperties(rootProject.file("versions.properties").path)
configure<ConstantsExtension> {
constantsObject(
pkg = folder.joinToString("."),
className = "GeneratedConstants"
) {
field("BUILD") value versionSuffix
field("VERSION") value fullVersion.substringBefore('-')
field("FULL_VERSION") value fullVersion
field("MAVEN_URL") value "https://nikky.moe/maven"
field("MAVEN_GROUP") value group.toString()
field("MAVEN_ARTIFACT") value project.name
field("MAVEN_SHADOW_CLASSIFIER") value Maven.shadowClassifier
}
}
}
val generateConstants by tasks.getting(GenerateConstantsTask::class) {
outputs.upToDateWhen { false }
kotlin.sourceSets["main"].kotlin.srcDir(outputFolder)
}
// TODO depend on kotlin tasks in the plugin too ?
tasks.withType<KotlinCompile> {
dependsOn(generateConstants)
}
}
idea {
module {
excludeDirs.add(file("run"))
}
}
afterEvaluate {
if (pluginManager.hasPlugin("application")) {
logger.lifecycle("apply shadowJar")
apply(plugin = "com.github.johnrengelman.shadow")
val runDir = rootProject.file("samples")
val run by tasks.getting(JavaExec::class) {
doFirst {
runDir.mkdirs()
}
workingDir = runDir
}
val runShadow by tasks.getting(JavaExec::class) {
doFirst {
runDir.mkdirs()
}
workingDir = runDir
}
val shadowJar by tasks.getting(ShadowJar::class) {
archiveBaseName.set(project.name)
archiveClassifier.set(Maven.shadowClassifier)
// archiveVersion.set(fullVersion)
// archiveFileName.set("${project.name.toLowerCase()}-$versionSuffix.${archiveExtension.getOrNull()}")
}
val build by tasks.getting(Task::class) {
dependsOn(shadowJar)
}
}
// publishing
apply(plugin = "maven-publish")
val sourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}
val javadoc by tasks.getting(Javadoc::class) {}
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
from(javadoc)
}
configure<PublishingExtension> {
publications {
create<MavenPublication>("default") {
from(components["java"])
artifact(sourcesJar.get())
artifact(javadocJar.get())
artifactId = project.name.toLowerCase()
}
if (pluginManager.hasPlugin("com.github.johnrengelman.shadow")) {
create("shadow", MavenPublication::class.java) {
(project.extensions.getByName("shadow") as ShadowExtension).component(this)
}
}
create<MavenPublication>("snapshot") {
this as org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal
version = defaultVersion + "-SNAPSHOT"
isAlias = true
from(components["java"])
artifact(sourcesJar.get())
artifact(javadocJar.get())
artifactId = project.name.toLowerCase()
}
if (pluginManager.hasPlugin("com.github.johnrengelman.shadow")) {
create("shadow-snapshot", MavenPublication::class.java) {
this as org.gradle.api.publish.maven.internal.publication.MavenPublicationInternal
version = defaultVersion + "-SNAPSHOT"
isAlias = true
(project.extensions.getByName("shadow") as ShadowExtension).component(this)
}
}
}
repositories {
maven("https://nikky.moe/mavenupload") {
name = "nikkyMaven"
val mavenUsername: String? = System.getenv("MAVEN_USERNAME")
val mavenPass: String? = System.getenv("MAVEN_PASSWORD")
if (mavenUsername != null && mavenPass != null) {
credentials {
username = mavenUsername
password = mavenPass
}
}
}
}
}
apply(from = "${rootDir.path}/mavenPom.gradle.kts")
}
}
dependencyGraphGenerator {
generators += com.vanniktech.dependency.graph.generator.DependencyGraphGeneratorExtension.Generator(
name = "projects",
include = { dep ->
logger.lifecycle("include: $dep ${dep.moduleGroup} ${dep.parents}")
dep.moduleGroup == rootProject.group || dep.parents.any { it.moduleGroup == rootProject.group }
},
projectNode = { node, b ->
node
.add(
guru.nidi.graphviz.attribute.Color.SLATEGRAY,
guru.nidi.graphviz.attribute.Color.AQUAMARINE.background().fill(),
guru.nidi.graphviz.attribute.Style.FILLED
)
},
includeProject = { project ->
logger.lifecycle("project: $project")
// project.buildFile.exists()
true
},
dependencyNode = { node, dep ->
logger.lifecycle("dep node $dep ${dep::class}")
node
}
)
}