diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 939b3f6583b..8a18ba8f62c 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -38,20 +38,46 @@ tasks { } } - register("listmodels") { - for (prop in System.getProperties().iterator()) { - val key = prop.key.toString() - if (key.startsWith("ai.djl.")) { - systemProperty(key, prop.value) - } + distTar { enabled = false } + distZip { enabled = false } + + sourceSets.main.get().java.files + .filter { it.text.contains("public static void main(String[] args)") } + .map { + it.path.substringAfter("java${File.separatorChar}").replace(File.separatorChar, '.') + .substringBefore(".java") } - if (!systemProperties.containsKey("ai.djl.logging.level")) { - systemProperty("ai.djl.logging.level", "debug") + .forEach { className -> + val taskName = className.substringAfterLast(".") + + register(name = taskName) { + classpath = sourceSets.main.get().runtimeClasspath + mainClass = className + group = "application" + for (prop in System.getProperties().iterator()) { + val key = prop.key.toString() + if (key.startsWith("ai.djl.")) { + systemProperty(key, prop.value) + } + } + if (!systemProperties.containsKey("ai.djl.logging.level")) { + systemProperty("ai.djl.logging.level", "debug") + } + + allJvmArgs = allJvmArgs + listOf( + // kryo compatability + // from https://github.com/EsotericSoftware/kryo/blob/cb255af4f8df4f539778a325b8b4836d41f84de9/pom.xml#L435 + "--add-opens=java.base/java.lang=ALL-UNNAMED", + "--add-opens=java.base/java.lang.invoke=ALL-UNNAMED", + "--add-opens=java.base/java.net=ALL-UNNAMED", + "--add-opens=java.base/java.nio=ALL-UNNAMED", + "--add-opens=java.base/java.time=ALL-UNNAMED", + "--add-opens=java.base/java.util=ALL-UNNAMED", + "--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED", + "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED", + "--add-opens=java.base/sun.util.calendar=ALL-UNNAMED" + ) + } } - classpath = sourceSets.main.get().runtimeClasspath - mainClass = "ai.djl.examples.inference.ListModels" - } +} - distTar { enabled = false } - distZip { enabled = false } -} \ No newline at end of file