Skip to content

Commit

Permalink
[examples] Adds gradle tasks for each example (#3466)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu authored Sep 12, 2024
1 parent 7e3d2a5 commit f7165f9
Showing 1 changed file with 40 additions and 14 deletions.
54 changes: 40 additions & 14 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,46 @@ tasks {
}
}

register<JavaExec>("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<JavaExec>(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 }
}

0 comments on commit f7165f9

Please sign in to comment.