diff --git a/build.gradle.kts b/build.gradle.kts index 1a6c2f7..b62a7c3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ - plugins { java - id("org.jetbrains.kotlin.jvm") version "1.6.0" + id("org.jetbrains.kotlin.jvm") version "1.6.10" + id("org.graalvm.buildtools.native") version "0.9.9" application } @@ -11,9 +11,23 @@ repositories { dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib") - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0") } application { mainClass.set("lv.n3o.aoc2021.Main") +} + +tasks.named("run").configure { + outputs.upToDateWhen { false } +} + +graalvmNative { + binaries { + named("main") { + agent { + enabled.set(true) + } + } + } } \ No newline at end of file diff --git a/readme.md b/readme.md index 4fad358..66340e3 100644 --- a/readme.md +++ b/readme.md @@ -4,4 +4,6 @@ See [AoC 2021](https://adventofcode.com/2021/) for puzzles. Inputs are usually defined in input files in `src/main/resources/` (`i{nn}.txt` wheren `{nn}` is 0-padded day number). -To run all, use `./gradlew run` (or `gradlew.bat run` on Windows) \ No newline at end of file +To run all, use `./gradlew run` (or `gradlew.bat run` on Windows) + +To compile native image using GraalVM, run `nativeCompile` task. Result will be placed in `build/native/nativeCompile/` \ No newline at end of file diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 161d3df..0000000 --- a/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -rootProject.name = 'aoc2021' - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..9037e2a --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,7 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + } +} +rootProject.name = "aoc2021" \ No newline at end of file diff --git a/src/main/kotlin/lv/n3o/aoc2021/Task.kt b/src/main/kotlin/lv/n3o/aoc2021/Task.kt index 97f0a19..e5e55ad 100644 --- a/src/main/kotlin/lv/n3o/aoc2021/Task.kt +++ b/src/main/kotlin/lv/n3o/aoc2021/Task.kt @@ -39,7 +39,7 @@ abstract class Input { class ClasspathInput(val name: String) : Input() { override fun readInput(): String { - with(this::class.java.classLoader.getResourceAsStream(name)!!) { + with(javaClass.getResourceAsStream(name) ?: ClassLoader.getSystemClassLoader().getResourceAsStream(name)) { return bufferedReader(Charsets.UTF_8).readText() } } diff --git a/src/main/kotlin/lv/n3o/aoc2021/main.kt b/src/main/kotlin/lv/n3o/aoc2021/main.kt index b7b089e..e360fda 100644 --- a/src/main/kotlin/lv/n3o/aoc2021/main.kt +++ b/src/main/kotlin/lv/n3o/aoc2021/main.kt @@ -17,7 +17,7 @@ private const val REPEAT_RUNS = 1 private fun ci(number: Int, expectedA: String, expectedB: String): TestCase { val paddedNumber = "$number".padStart(2, '0') val className = "T$paddedNumber" - val inputFile = "i$paddedNumber.txt" + val inputFile = "/i$paddedNumber.txt" val taskClass = Class.forName("lv.n3o.aoc2021.tasks.$className") val constructor: (Input) -> Task = { input -> taskClass.getConstructor(Input::class.java).newInstance(input) as Task }