this kind of hint isn’t helpful
You don’t find it helpful that I tell you that you are following bad practice and what you should do instead?
How comes you find that not helpful? o_O
because the gradle documentation never goes beyond trivial examples
I don’t get how that is a “because” and I tend to strongly object. The docs are imho very big and also show some very advanced things. And in my opinion the Gradle docs are very good for a software tool’s doc.
In this particular case, the use of evaluationDependsOn
is mentioned in the documentation without any indication that this might be bad practice or indicating what might be a “better practice”.
It also still shows to use task("...")
to create task at some places which is bad practice and shows that you can use afterEvaluate { ... }
even though it is highly discouraged, or how legacy script plugins work that have many quirks and should be avoided.
Generally any documentation is almost always almost instantly outdated, that’s just how the world works unfortunatley.
And things that are bad-practice are often not flagged as such in any documentation.
That doesn’t change that they are bad practice and should be avoided.
The documntation shows that the evaluationDependsOn
exists and how to use it if really needed, how it also shows many other things that you could do, as Gradle is extremely powerful and flexible. But with great power for the user, comes great responsibility for the user to use it wisely.
You are here in the forum to get help from people that are maybe more experienced. And one of these users told you it is bad practice to use that method and what better to do. Take the advice or ignore it, that’s fully up to you, it is your build and you have to live with the consequences like slower builds, harder to adopt isolated project once they become stable and thus waste muuuch of the time of anyone interacting with the build, and so on.
set the versions in the subprojects – based on information from git
Imho, that indeed is a quite unusual situation and a very bad idea.
I know a few poeple doing such things, but I personally think this is a very bad idea.
This ties the buildability to being in a Git worktree and if JGit is used even only to the main worktree and not any additional worktrees.
And if you ever change the VCS, you cannot checkout an old state and build properly, or if you export the sources to an archive and try to build from that wihtout Git available, you also cannot build properly.
…
But to everyone his self-created hell.
I have a task in the root project which has a configuration that depends on the versions of the subprojects. (Some things are done differently if the subprojects have snapshot versions.) This task is related to the whole project tree, i.e. it cannot be split and executed by the subprojects individually.
Well, I cannot give a concrete advice as you did not share enough information.
For example what is done with that information?
Do you really need the configuration at configuration time?
If the task just does different things depending on those versions, you can for example create a configuration, depend on the other projects, give the resolution result of that configuration as input to the task, and then at execution time check if there are any snapshot versions in project dependencies. This can even be done in a configuration-cache safe way, …
Just to explain one of the possibilities, depending on concrete situation.