-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
73 lines (54 loc) · 1.55 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
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
plugins {
kotlin("jvm") version "1.7.21"
}
group = "de.nxll.aoc2022"
version = "1.0"
val currentDay = 15
repositories {
mavenCentral()
}
dependencies {
}
kotlin {
target {
compilations {
val common by creating
for (day in 1..currentDay) {
val dayCompilation = create("day_$day") {
associateWith(common)
generateAOCBaseStructure(day)
}
tasks.create<JavaExec>("runDay$day") {
group = "aoc"
mainClass.set("Day${day}Kt")
classpath = dayCompilation.runtimeDependencyFiles
}
}
all {
kotlinOptions {
jvmTarget = "17"
}
}
}
}
jvmToolchain(17)
}
fun KotlinCompilation<*>.generateAOCBaseStructure(day: Int) {
val kotlinDir = defaultSourceSet.kotlin.sourceDirectories.first { it.name == "kotlin" }
val resourcesDir = defaultSourceSet.resources.srcDirs.first()
val mainFile = kotlinDir.resolve("Day${day}.kt")
val inputFile = resourcesDir.resolve("input.txt")
kotlinDir.mkdirs()
resourcesDir.mkdirs()
inputFile.createNewFile()
if (mainFile.createNewFile()) {
val templateContent = """
// AOC Day $day
fun main() {
println("Hello Day $day")
}
""".trimIndent()
mainFile.writeText(templateContent)
}
}