Adam
04/22/2025, 5:53 PMsystemProperty("...", "...")
work, but these are eager and I want to avoid them.
Weirdly when I print all properties in the application they appear under a different property - sun.java.command=org.example.AppKt -DsecretFile=/Users/dev/my-project/secret-file
.
I think it's weird there's an inconsistency. I would expect both approaches to work the same.
Also, I think it's weird that logging commandLine
returns a null
as the first element: [:run] running task [null, -DsecretFile=/Users/dev/my-project/secret-file]
plugins {
kotlin("jvm") version "2.1.20"
application
}
tasks.run.configure {
val secretFile = layout.projectDirectory.file("secret-file")
inputs.file(secretFile)
argumentProviders += CommandLineArgumentProvider {
listOf("-DsecretFile=${secretFile.asFile.absoluteFile.invariantSeparatorsPath}")
}
systemProperty("secretFileWorks", secretFile.asFile.absoluteFile.invariantSeparatorsPath)
doFirst {
println("[$path] running task $commandLine")
}
}
Gradle version is 8.13Adam
04/22/2025, 6:19 PMVampire
04/22/2025, 8:31 PMargumentProviders
is for arguments to your main method, you will find it in your args
.
What you wanted to use is jvmArgumentProviders
. :-)