-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle.kts
134 lines (118 loc) · 4.63 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
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.9.20"
id("com.gorylenko.gradle-git-properties") version "2.4.2"
id("org.jlleitschuh.gradle.ktlint") version "12.1.1"
id("io.gitlab.arturbosch.detekt").version("1.22.0")
}
group = "ch.derlin"
// Get the version from version.txt. It should NOT contain -SNAPSHOT, but be THE LATEST RELEASED version.
// The version will be computed automatically as <next-patch-version>-SNAPSHOT.
// In case `-Dsnapshot=false` is passed to the gradle command, the version will be used as is (useful during release)
version =
file("version.txt").readText().let {
val match = requireNotNull("(\\d+\\.\\d+\\.)(\\d+)".toRegex().find(it)) { "Could not extract version from version.txt" }
if (System.getProperty("snapshot") in listOf("0", "false")) {
match.value
} else {
match.groupValues[1] + (match.groupValues[2].toInt() + 1) + "-SNAPSHOT"
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.yaml:snakeyaml:2.2")
implementation("com.github.ajalt.clikt:clikt:4.4.0")
implementation("com.microsoft.playwright:playwright:1.45.1")
implementation("io.github.microutils:kotlin-logging-jvm:3.0.5")
implementation("ch.qos.logback:logback-classic:1.5.6")
testImplementation(kotlin("test"))
testImplementation("com.willowtreeapps.assertk:assertk:0.28.1")
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
tasks.jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
val noPlaywright = project.hasProperty("noPlaywright")
if (noPlaywright) {
archiveBaseName.set("${archiveBaseName.get()}_no_local")
}
manifest {
attributes += "main-Class" to "ch.derlin.dcvizmermaid.MainKt"
if (noPlaywright) {
// set default renderer to mermaid.ink if ran with the argument -PnoPlaywright
attributes += "env" to mapOf("MERMAID_RENDERER" to "mermaid.ink")
}
}
from(
configurations.runtimeClasspath.get()
// exclude playwright dependencies if ran with the argument -PnoPlaywright
.filter { !(noPlaywright && it.path.contains("/com.microsoft.playwright/")) }
.map { if (it.isDirectory) it else zipTree(it) },
)
}
abstract class ExecutableJarTask : DefaultTask() {
// This custom task will prepend the content of a bash launch script
// at the beginning of a jar, and make it executable (chmod +x)
@InputFiles
var originalJars: ConfigurableFileTree = project.fileTree("${project.buildDir}/libs") { include("*.jar") }
@OutputDirectory
var outputDir: File = project.buildDir.resolve("bin") // where to write the modified jar(s)
@InputFile
var launchScript: File = project.rootDir.resolve("launch.sh") // script to prepend
@TaskAction
fun createExecutableJars() {
project.mkdir(outputDir)
originalJars.forEach { jar ->
outputDir.resolve(jar.name).run {
outputStream().use { out ->
out.write(launchScript.readBytes())
out.write(jar.readBytes())
}
setExecutable(true)
println("created executable: $path")
}
}
}
}
tasks.register<ExecutableJarTask>("exec-jar") {
// dependsOn("jar") // since we have two flavors (-PnoPlaywright), don't depend on jar
launchScript = project.rootDir.resolve("bin/launcher.sh")
}
tasks.test {
useJUnitPlatform {
if (project.hasProperty("excludeTags")) {
excludeTags(project.properties["excludeTags"] as String)
}
if (project.hasProperty("includeTags")) {
excludeTags(project.properties["includeTags"] as String)
}
}
outputs.upToDateWhen { false } // always run tests !
testLogging {
// get actual information about failed tests in the console
// should be used inside
showStackTraces = true
showCauses = true
showExceptions = true
exceptionFormat = TestExceptionFormat.FULL
}
filter {
// use ./gradlew test -Pdocs to generate also the docs
if (project.hasProperty("docs")) {
environment(mapOf("GEN_DOCS" to "1"))
// excludeTestsMatching("*Generator*")
}
}
}
gitProperties {
gitPropertiesName = "info.properties"
keys = listOf("git.build.version", "git.branch", "git.commit.id", "git.commit.message.short", "git.commit.time", "git.dirty")
}
detekt {
config = files(".detekt.yaml")
buildUponDefaultConfig = true
}