Not sure if this is a gradle problem or not, but I...
# gradle
j
Not sure if this is a gradle problem or not, but I'm trying to pass a gradle property (
project.version
) through to read it in my kotlin module. I've tried every permutation of
setProperty
and
environment
(within
tasks.withType<JavaExec> {}
), and just a blanket
System.setProperty()
, in both the root build.gradle.kts as well as the module build.gradle.kts. No matter what, my corresponding
System.getProperty()
or
System.getenv()
is returning null in my kotlin file. Anyone got any pointers?
m
Can you clarify ? Do you want to read
project.version
at runtime?
If you're writing a CLI app, you can certainly customize the
run
task to put the version in the environment but that only works if you invoke from Gradle (
./gradlew run
)
If you're writing an Android app, you'll most likely have to generate a source file that contains the version and is compiled with the rest of your Kotlin sources
in both the root build.gradle.kts as well as the module build.gradle.kts.
Oh, I missed that, looks like it's all Gradle
j
At buildtime. Not an Android app. I'm developing a kotlin SDK, and would like the project.version to be accessible from within the SDK (so I can include it in headers sent to my backend)
m
Ah ok then it's not all Gradle. You'll need to codegen your way
j
Awesome, thanks! That is.... surprising that it's not easier 😅
m
Because you don't know what environment your SDK is going to be run in I don't think there are many other solutions
Your build environment != your SDK runtime environment
There are Gradle plugins to help with this, let me check
j
very good point! I wasn't thinking about it like that.
m
j
thanks so much for your help!
m
Sure thing!