This message was deleted.
# community-support
s
This message was deleted.
m
Short answer: you can't know. Long answer: there may be many tasks which require the version to be set, not just jar. For example, you may have a task which reads the version to generate a properties file. Or you can have a task which reads the version to generate a source file (so before
compileJava
). Or, you can have plugins which reason on the version to configure things differently (e.g if SNAPSHOT is used, etc...). It is unfortunate that there's no
Provider<String>
for
version
and
group
yet, which would be a better fit for your use case, but in general, you simply cannot know.
c
So basically you are suggesting we set the version right after project evaluation?
I would have opted for assemble otherwise
m
This is far too late. Do it as early as possible.
and btw, don't "do it at `assemble`" or any other task. This isn't about tasks, you don't even know which tasks will be called by a user. I almost never call
assemble
. I call tasks I need for a particular job. e.g
test
,
jar
or even sometimes just
compileJava
.
t
Note that
project.version
is an
Object
, so you can actually make it compute (and memoize) its
toString()
dynamically. Not saying you should do it that way, but it works (or at least, it worked!) https://github.com/tbroyer/gradle-incap-helper/blob/21afe339d6281ee040db5547cbded7ff21b59ae8/build-logic/src/main/kotlin/VersionFromGit.kt https://github.com/tbroyer/gradle-incap-helper/blob/21afe339d6281ee040db5547cbded7ff21b59ae8/build.gradle.kts
m
Yeah, poor man's
Provider
😄
I've seen plugins which assume
version
is a
String
though
c
I am currently using tasks and the caching mechanism to calculate the version So what i have is a executeVersionCalculation -> writes and stores cached file, readVersion (reads the cached file) and setVersion (sets the version to project.version)
That doesn't seem to be the best approach then
How would you suggest implementing the caching then, if not using tasks and doing it directly in the Plugin?
m
You should use a build service probably.