feat: add a JVM CLI sample

This commit is contained in:
Harsh Shandilya 2023-08-18 06:33:43 +05:30
parent fb9d02958a
commit cd936e1e91
3 changed files with 51 additions and 3 deletions

View File

@ -0,0 +1,26 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
embeddedKotlin("jvm")
application
}
group = "dev.msfjarvis.tracelog"
version = "1.0.0-SNAPSHOT"
application {
mainClass = "dev.msfjarvis.tracelog.sample.MainKt"
}
tasks.withType<KotlinCompile>().configureEach {
compilerOptions.freeCompilerArgs.addAll(
"-P",
"plugin:dev.msfjarvis.tracelog:loggerFunction=dev.msfjarvis.tracelog.sample.recordMessage",
)
}
dependencies {
kotlinCompilerPluginClasspath(projects.compilerPlugin)
implementation(projects.annotations)
}

View File

@ -0,0 +1,21 @@
package dev.msfjarvis.tracelog.sample
import dev.msfjarvis.tracelog.annotations.DebugLog
private val messages = arrayListOf<String>()
fun main() {
debuggableFunction("First parameter")
println("Captured messages:")
println(messages.joinToString("\n"))
}
@Suppress("Unused") // Used by the generated bytecode
fun recordMessage(message: Any?) {
messages += message.toString()
}
@DebugLog
fun debuggableFunction(p0: String): String {
return "Debugging is cool!"
}

View File

@ -14,9 +14,10 @@ plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
rootProject.name = "tracelog"
include(
"annotations",
"compiler-plugin",
"gradle-plugin",
"annotations",
"compiler-plugin",
"gradle-plugin",
"sample-jvm",
)
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")