We have a multi project build in the same repository and we’re trying to publish artifacts conditionally, based on which project was changed.
So far what we have is a task that looks at the current commit, determines the files that were changed and thus the projects that need to be republished - this task then invokes setTasks with a list of “release” tasks only for the changed projects, i.e.:
def tasks = [":projectA:release",";projectB:release"]
The problem here is that the release task depends on project.version, which is set during the configuration phase - and we need to be able to modify that field conditionally, based on whether the project in question needs to be published or not.
What we have so far is a pretty ugly workaround, where we use System.setProperty to set the list of changed projects, making it globally acccessible across all subsequent build phases, and then in the build.gradle of each project we do something like:
project.version = something
project.version = somethingElse
This doesn’t strike me as a very “gradle” way of doing this - I am wondering if it’s possible somehow to conditionally control the configuration of the projects when invoking tasks with setTasks? Or maybe I should look at a different approach altogether…?