forked from iamgio/quarkdown
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
210 lines (173 loc) · 4.82 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
210 lines (173 loc) · 4.82 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.ByteArrayOutputStream
import java.time.Year
plugins {
kotlin("jvm") version "2.1.20"
id("org.jetbrains.dokka") version "2.0.0"
id("org.jlleitschuh.gradle.ktlint") version "12.2.0"
id("com.gradleup.shadow") version "8.3.6"
id("com.github.ben-manes.versions") version "0.52.0"
application
}
group = "com.quarkdown"
// Fetch the project version from the latest v* git tag
val lastVersionTag: String? by lazy {
try {
exec {
commandLine("git", "fetch", "--tags", "-f")
}
val stdout = ByteArrayOutputStream()
exec {
commandLine("git", "describe", "--tags", "--match", "v*", "--abbrev=0")
standardOutput = stdout
}
stdout.toString().trim().removePrefix("v")
} catch (_: Exception) {
null
}
}
version = lastVersionTag ?: "0.0.0"
tasks.register("printVersion") {
doLast {
println(project.version)
}
}
allprojects {
repositories {
mavenCentral()
}
}
subprojects {
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "org.jlleitschuh.gradle.ktlint")
}
// Fat JAR / Distribution dependencies
gradle.projectsEvaluated {
dependencies {
subprojects.forEach {
when {
it.extra.has("noRuntime") && it.extra["noRuntime"] == true -> {
compileOnly(it)
}
else -> implementation(it)
}
}
}
}
application {
mainClass.set("com.quarkdown.cli.QuarkdownCliKt")
}
ktlint {
version.set("1.5.0")
}
// Dokka
/*dependencies {
subprojects.forEach {
dokka(it)
}
}*/
dokka {
dokkaPublications.html {
outputDirectory.set(
layout.buildDirectory
.file("docs")
.get()
.asFile,
)
}
}
/**
* Whether [project] uses the Quarkdoc plugin, which means its documentation must be included in the distribution zip.
*/
fun usesQuarkdoc(project: Project): Boolean {
val quarkdoc = project(":quarkdown-quarkdoc")
return project.configurations
.asSequence()
.flatMap { it.dependencies }
.filterIsInstance<ProjectDependency>()
.any { it.dependencyProject == quarkdoc }
}
tasks.register("quarkdocGenerate") {
group = "documentation"
description = "Generates the Quarkdoc documentation for modules that include the Quarkdoc plugin."
dependencies {
subprojects.filter(::usesQuarkdoc).forEach {
dokka(it)
}
}
dependsOn(tasks.dokkaGenerate)
}
tasks.register("quarkdocGenerateAll") {
group = "documentation"
description = "Generates the Quarkdoc documentation for all modules."
dependencies {
subprojects.forEach {
dokka(it)
}
}
dependsOn(tasks.dokkaGenerate)
}
allprojects {
fun asset(path: String): File = project(":quarkdown-quarkdoc").projectDir.resolve("src/main/resources/$path")
dokka {
pluginsConfiguration.html {
val year = Year.now().value
footerMessage.set("© $year Quarkdown")
customAssets.from(*asset("assets/images").listFiles())
customStyleSheets.from(asset("styles/stylesheet.css"))
}
}
}
// Tasks
tasks.build {
dependsOn("shadowJar")
}
tasks.jar {
enabled = false // The jar is generated by shadowJar
}
tasks.test {
useJUnitPlatform()
dependsOn(tasks.ktlintCheck)
}
tasks.distZip {
val baseName = archiveBaseName.get()
archiveVersion.set("")
// The module 'libs' contains .qmd library files that are saved in the lib/qmd directory of the distribution zip.
val librariesModule = project(":quarkdown-libs")
into("$baseName/lib/qmd") {
from(librariesModule.file("src/main/resources")) {
include("*.qmd")
}
}
// Include the generated Dokka documentation in the 'docs' directory.
tasks.named("quarkdocGenerate").let { dokkaTask ->
dependsOn(dokkaTask)
val dokkaOutputDir = layout.buildDirectory.file("docs")
from(dokkaOutputDir) {
into("$baseName/docs")
}
}
}
tasks.wrapper {
gradleVersion = "8.3"
distributionType = Wrapper.DistributionType.ALL
}
tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
tasks.withType<ShadowJar> {
archiveVersion.set("")
archiveClassifier.set("")
}
tasks.withType<DependencyUpdatesTask> {
rejectVersionIf {
sequenceOf("alpha", "beta", "preview", "-m", "-rc").any {
candidate.version.contains(it, ignoreCase = true)
}
}
}