Skip to content

Commit 0baadc6

Browse files
committed
WIP
1 parent 4e493e2 commit 0baadc6

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

README.adoc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ Unfortunately, this doesn't actually work because the implementation uses its ow
1616
## The solution
1717
The workaround is to unpack the jars used by the scripts.
1818

19+
## Motivation
20+
Kotlin scripts in my application for evaluations etc. are a powerful option.
21+
Scripts can be adapted at runtime.
22+
But please note: scripts must be well secured because they may have full access to the application.
23+
24+
## State of the art (call for improvements)
25+
I tried several approaches:
26+
- passing my own classLoader (doesn't work)
27+
- unpacking jars in the SpringBoot fatjar (does work), and
28+
- automatically copying jars from the fatjar to the local file system (will follow).
29+
I will show all approaches here and call for improvements.
30+
1931
## Gradle vs. Maven
2032
I migrated my project (ProjectForge) from *Maven* to *Gradle*. In principle, unpacking fatjars with maven is also possible, but it is incredibly more complicated.
2133

@@ -27,6 +39,11 @@ This project contains sample code including a gradle setup that implements a min
2739
### Module: application
2840
The Spring Boot application with gradle configuration to unpack the jars.
2941

42+
The current solution:
43+
44+
- Variables can be passed. This is useful, for example, if users are required in ThreadLocal for the user authentication of application functions used.
45+
- The script is automatically stopped after a defined runtime. This avoids endless scripts or unwanted long-running scripts.
46+
3047
### Module: business
3148
A simple module with a class that is used by the Kotlin script.
3249

@@ -36,4 +53,3 @@ Just run:
3653
1. `./gradlew clean build`
3754
2. `java -jar application/build/libs/application-0.0.1.jar`
3855
3. See the output in the console.
39-
4. Use CTRL+C to stop the application.

application/src/main/kotlin/de/micromata/kotlinscripting/DemoApplication.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package de.micromata.kotlinscripting
22

3-
import org.jetbrains.kotlin.ir.types.IdSignatureValues.result
3+
import org.springframework.boot.ExitCodeGenerator
4+
import org.springframework.boot.SpringApplication
45
import org.springframework.boot.autoconfigure.SpringBootApplication
56
import org.springframework.boot.runApplication
67
import kotlin.script.experimental.api.ResultValue
78
import kotlin.script.experimental.api.ResultWithDiagnostics
89
import kotlin.script.experimental.api.valueOrNull
910

11+
1012
@SpringBootApplication
1113
class DemoApplication {
1214

@@ -33,6 +35,8 @@ class DemoApplication {
3335
} else {
3436
println("*** Script result: $result")
3537
}
38+
System.exit(0) // Not an elegant way, but here it is enough.
39+
3640
}
3741
}
3842
}

0 commit comments

Comments
 (0)