Slackbot
06/14/2022, 8:49 AMSteve Ebersole
06/14/2022, 9:00 AMSteve Ebersole
06/14/2022, 9:01 AMplugin{}
version has not yet been setSteve Ebersole
06/14/2022, 9:02 AMSteve Ebersole
06/14/2022, 9:08 AMSteve Ebersole
06/14/2022, 9:09 AMephemient
06/14/2022, 9:12 AMprojevtVersion.set(project.provider { project.version.toString() })
ephemient
06/14/2022, 9:14 AM.convention
instead of .set
, as mentioned, but that doesn't change how to postpone the providerSteve Ebersole
06/14/2022, 9:14 AMSteve Ebersole
06/14/2022, 9:15 AMSteve Ebersole
06/14/2022, 9:15 AMSteve Ebersole
06/14/2022, 9:16 AMmyTask.getProjectVersion().convention(project.getVersion())
Steve Ebersole
06/14/2022, 9:17 AMSteve Ebersole
06/14/2022, 9:18 AMit.projectVersion.set(...)
implies it is already a Property I guessSteve Ebersole
06/14/2022, 9:18 AMSteve Ebersole
06/14/2022, 9:18 AMSteve Ebersole
06/14/2022, 9:18 AMCraig
06/14/2022, 9:20 AMNot sure I believe tht "just broke",Haha, fair enough. I swear it's true though 🙂
why do you even set it out of curiosity? a task always has access to the projectThat's a good question. I used to simply reference it for quite a while, no problem. And then gradle started giving me deprecation warnings about how I shouldn't access it directly. This was a while ago so I don't remember exactly.
Steve Ebersole
06/14/2022, 9:20 AMSteve Ebersole
06/14/2022, 9:21 AMSteve Ebersole
06/14/2022, 9:21 AMProperty<JavaVersion>
Steve Ebersole
06/14/2022, 9:22 AMCraig
06/14/2022, 9:24 AMOh, that's looks cool. I can create a provider out of anything? And it will only get resolved when the task runs? Perfect. I think that will solve my immediate problem. The question remains though why I had to turn group and version into properties in the first place. I might revert that change and see what gradle has to say.projevtVersion.set(project.provider { project.version.toString() })
Steve Ebersole
06/14/2022, 9:26 AMSteve Ebersole
06/14/2022, 9:27 AMSteve Ebersole
06/14/2022, 9:27 AMCraig
06/14/2022, 9:28 AMSteve Ebersole
06/14/2022, 9:28 AMplugins {}
applies your plugin (because that happens very early)
2. your plugin accesses the projects version
3. your script sets the versionCraig
06/14/2022, 9:28 AMSteve Ebersole
06/14/2022, 9:28 AMSteve Ebersole
06/14/2022, 9:29 AMSteve Ebersole
06/14/2022, 9:29 AMSteve Ebersole
06/14/2022, 9:29 AMCraig
06/14/2022, 9:30 AMCraig
06/14/2022, 9:30 AMCraig
06/14/2022, 9:34 AMit.projectVersion.set(project.version)
but I can't...Steve Ebersole
06/14/2022, 9:34 AMSteve Ebersole
06/14/2022, 9:35 AMCraig
06/14/2022, 9:35 AMSteve Ebersole
06/14/2022, 9:35 AMCraig
06/14/2022, 9:36 AMit.projectVersion.convention(project.version.toString())
Steve Ebersole
06/14/2022, 9:36 AMCraig
06/14/2022, 9:36 AMSteve Ebersole
06/14/2022, 9:36 AMSteve Ebersole
06/14/2022, 9:37 AMSteve Ebersole
06/14/2022, 9:37 AMSteve Ebersole
06/14/2022, 9:37 AMCraig
06/14/2022, 9:38 AMSteve Ebersole
06/14/2022, 9:39 AMSteve Ebersole
06/14/2022, 9:39 AMSteve Ebersole
06/14/2022, 9:39 AMCraig
06/14/2022, 9:39 AM<T> Provider<T> provider(Callable<T> var1);
Steve Ebersole
06/14/2022, 9:40 AMSteve Ebersole
06/14/2022, 9:40 AMCraig
06/14/2022, 9:41 AMSteve Ebersole
06/14/2022, 9:41 AMVampire
06/14/2022, 9:41 AMand use a conventionUsing
convention(...)
or set(...)
/ value(...)
both is fine.
It has different semantics.
If later someone does set(x)
and then set(null)
, with a convention(...)
it is effective again, with set(...)
or value(...)
it would now be unset.
though actually, why do you even set it out of curiosity? a task always has access to the projectAccessing the
project
during task execution is deprecated as it is incompatible with configuration cache.
Besides that it can easily be a task input by having a dedicated property.
If you do it like OP wrote, then it is delayed until the task is configured.
If you do it with a provider it is delayed until the property is queried, so potentially just at task execution time, so exactly what is needed here.
Or you could change the task toProperty<JavaVersion>
JavaVersion
to set the project version? o_O
Actually, I was wrong... version is a String... no
Steve Ebersole
06/14/2022, 9:42 AMVampire
06/14/2022, 9:42 AMString
Steve Ebersole
06/14/2022, 9:42 AMCraig
06/14/2022, 9:43 AMSteve Ebersole
06/14/2022, 9:43 AMVampire
06/14/2022, 9:43 AMObject
Steve Ebersole
06/14/2022, 9:43 AMSteve Ebersole
06/14/2022, 9:43 AMVampire
06/14/2022, 9:43 AMtoString()
of itSteve Ebersole
06/14/2022, 9:43 AMVampire
06/14/2022, 9:43 AMProperty
existedVampire
06/14/2022, 9:44 AMVampire
06/14/2022, 9:44 AM"undefined"
which is its default valueVampire
06/14/2022, 9:44 AMgradle.properties
which I usually do if I don't need dynamic calculation, then it indeed was you.Steve Ebersole
06/14/2022, 9:45 AMVampire
06/14/2022, 9:45 AMgradle.properties
and then in the code set version
to a more capable object, that in its toString
just returns the version but has additional methods like getting the main release version or determining whether it is a snapshot version, ...Steve Ebersole
06/14/2022, 9:46 AMSteve Ebersole
06/14/2022, 9:46 AMVampire
06/14/2022, 9:47 AMgradle.properties
so that it is set as early as possible for any early consumers and this way it is also reliably set for all projects in the build and an automatic release process also has it easier to increase the version.Craig
06/14/2022, 9:47 AMAccessing theThanks for the input. I knew I changed it for a reason.during task execution is deprecated as it is incompatible with configuration cache.project
If you do it like OP wrote, then it is delayed until the task is configuredWhich was working fine for me until recently. I can shuffle things around and register tasks in
afterEvaluate
but I think the better solution is to delay the reading of group and version until the latest possible.Steve Ebersole
06/14/2022, 9:47 AMSteve Ebersole
06/14/2022, 9:48 AMCraig
06/14/2022, 9:49 AMI usually do it inThat's yet another file that defines the build. I even grumble at having to split my GAV up by putting the project 'name' in settings.gradle. Yes, I used to use maven, and the trio were always sitting nicely together at the top of the pom. (I'm sure there are good reasons for the way it works now).gradle.properties
Vampire
06/14/2022, 9:49 AMand register tasks inPlease don't. AnyafterEvaluate
afterEvaluate
you use should make your heart bleed.
It is usually just symptom treatment.
The provider is exactly what you want.
It maybe as just accidentally that it worked before.
but I think the better solution is to delay the reading of group and version until the latest possible.Exactly
Craig
06/14/2022, 9:51 AMand register tasks inafterEvaluate
> Please don'tNoted. I will use my new
provider(Callable)
powers to solve all my problems.Vampire
06/14/2022, 9:51 AMI even grumble at having to split my GAV up by putting the project 'name' in settings.gradle.Well, you don't have to split them. You can define your full GAV in the publishing configuration. Using the project group, project version and project name are just the conventions. But Gradle is very flexible and if you want the trio to be together, you are free to do so.
Vampire
06/14/2022, 9:52 AMSteve Ebersole
06/14/2022, 9:54 AMYes, I used to use maven, and the trio were always sitting nicely together at the top of the pom. (I'm sure there are good reasons for the way it works now).Did you enjoy duplicating versions everywhere throughout a multi-project build too? 😉
Craig
06/14/2022, 9:54 AMYou can define your full GAV in the publishing configurationRight, ok. That trips me out a little. I've always thought of the three as intrinsic to the build. But gradle doesn't care until publishing the jar I suppose. But you do require a settings.gradle don't you?
Steve Ebersole
06/14/2022, 9:55 AMVampire
06/14/2022, 9:56 AMsettings.gradle
, yes.
But you don't need to set a name in it.
The default is the directory name, so it usually makes sense to have a name defined in there.
But you don't have to.Vampire
06/14/2022, 9:57 AMgroup
indeed is only relevant for publishing.
If you don't want to publish or developing an end product,
setting the group
actually is pointless.
(Unless some plugin you use thinks it needs it)Vampire
06/14/2022, 9:58 AMversion
could be left out if you don't want to publish and are ok with the built artifacts not to have a version in their name for example.Craig
06/14/2022, 9:58 AM