Zyle Moore
03/30/2025, 7:11 PMmain
method in the JVM Target, and pass args to it. I've found stackoverflow answers talk about just running main
, or passing args from the gradle command line to the gradle task, or using the java
or application
plugins, or making an executable fatjar, or setting system properties. None of which I feel like should be necessary to just do what's already working (jvmRun) with some args.Zyle Moore
03/30/2025, 7:13 PMzymus@abyss:~/github/cultoftheancestormoth$ ./gradlew :cotam:jvmRun -DmainClass=games.studiohummingbird.cultoftheancestormoth.CotamKt
> Task :cotam:jvmRun
Usage: cotam [<options>] <command> [<args>]...
Options:
-h, --help Show this message and exit
Commands:
drudge
librarian
adept
example
load
BUILD SUCCESSFUL in 1s
6 actionable tasks: 1 executed, 5 up-to-date
Zyle Moore
03/30/2025, 7:14 PMzymus@abyss:~/github/cultoftheancestormoth$ ./gradlew :cotam:jvmRun -DmainClass=games.studiohummingbird.cultoftheancestormoth.CotamKt load
FAILURE: Build failed with an exception.
* What went wrong:
Task 'load' not found in root project 'cultoftheancestormoth' and its subprojects.
* Try:
> Run gradlew tasks to get a list of available tasks.
> For more on name expansion, please refer to <https://docs.gradle.org/8.6/userguide/command_line_interface.html#sec:name_abbreviation> in the Gradle documentation.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at <https://help.gradle.org>.
BUILD FAILED in 931ms
Sebastian Schuberth
03/30/2025, 8:30 PMZyle Moore
03/30/2025, 9:08 PMmain
correctly, but I still can't see how to pass any args to that main.Sebastian Schuberth
03/31/2025, 7:12 AM--args="options for main"
task option.tapchicoma
03/31/2025, 8:15 AMapplicationDefaultJvmArgs
to pass arguments for the main
functiontapchicoma
03/31/2025, 8:16 AMjvmRun
task is mostly needed for the IDE to run random code from the given projectSebastian Schuberth
03/31/2025, 8:25 AMjvmRun
for that purpose?tapchicoma
03/31/2025, 8:27 AMargs
input to configure run arguments.Sebastian Schuberth
03/31/2025, 8:36 AMZyle Moore
03/31/2025, 5:45 PM--args="load"
worked for me. Using applicationDefaultJvmArgs
doesn't seem to pass to main
, as I get the same result as the failure case above.
Not working
kotlin {
jvm {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
binaries {
executable(KotlinCompilation.MAIN_COMPILATION_NAME) {
mainClass.set("games.studiohummingbird.cultoftheancestormoth.CotamKt")
applicationDefaultJvmArgs.set(listOf("load"))
}
}
}
}
Working
zymus@abyss:~/github/cultoftheancestormoth$ ./gradlew :cotam:runJvm -DmainClass=games.studiohummingbird.cultoftheancestormoth.CotamKt --args="load"
tapchicoma
03/31/2025, 6:44 PMtapchicoma
03/31/2025, 6:50 PMapplicationDefaultJvmArgs
passes arguments to the java
rather then to the application itself. Though --args="load"
should also work for runJvm
task.Zyle Moore
03/31/2025, 6:50 PMkotlin {
jvm {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
binaries {
executable(KotlinCompilation.MAIN_COMPILATION_NAME) {
mainClass.set("games.studiohummingbird.cultoftheancestormoth.CotamKt")
}
}
}
}
And I run
./gradlew :cotam:runJvm load
It tries to interpret "load" as another gradle command, but there isn't one. It's intent was to be an arg to the main
pointed to by :cotam:runJvm
.
But running ./gradlew :cotam:runJvm --args="load"
, it does what I need.tapchicoma
03/31/2025, 6:52 PMexecutable()
DSL JavaExec
task with your arguments. But if you would like to see such an option in the executable
DSL itself - please open a new Kotlin issueZyle Moore
03/31/2025, 6:55 PM./gradlew tasks
would show jvmRun
, but trying to use a tasks.named<JavaExec>("jvmRun")
kept throwing an error that the task didn't exist, so I presumed I was also doing something wrong there.