I am looking for a programatic way to set the version of any random Gradle project to a value that I know in advance.
I could also say I am looking for Gradle’s counterpart of mvn versions:set -DnewVersion=${myVersion}
.
Background: I am working on a port of srcdeps [1] to Gradle. Srcdeps is a tool that brings source dependencies to Java projects. This is how it works in Maven:
The GAV requests to the local Maven repository are intercepted by srcdeps. If the requested version ends with -SRC-revision-1234abcd (where 1234abcd is a sha1 of a git commit) and such a version is not available in the local Maven repo, then the commit is checked out to some local directory, mvn versions:set -DnewVersion=${myVersion}
is run followed by mvn install
and the freshly built artifact is returned to the dependent build.
Now, I am looking for a way to reach something similar with Gradle. Say, that the dependency project is a Gradle project, and I want to be able to build any random commit of it so that the resulting artifacts have the version that the dependent project is requesting. And it is important to note, that in an ideal case, I know nothing about how the *.gradle files of the depedency project are organized.
I first tried to follow the way how I do it with maven where (I) change version and (II) build are two separate steps. Googling has not brought any usable solution. This is what I learned so far, maybe you can correct me somewhere (I am new to Gradle, sorry for listing trivialities):
(1) There is probably no need to have someting like mvn versions:set
in Gradle, because the version is typically stored on one single location and manipulating it is easy enough so that that no tool is necessary for that.
(2) Although the location where the version is stored, is only one, it is not the case that the location is the same for all possible Gradle projects.
Moreover, the variety of the possible locations is twofold: (i) the version can live in various files (build.gradle, settings.gradle, others?) and (ii) because those files are scripts rather than any rigidly structured data files, the version can be set nearly anywhere in their syntax tree.
Because of (2), writing a reliable universal tool to set the version does not sound viable. Do you agree with this conclusion?
Can you see other possibilities how to reach what I need? I’d be ready to write a Gradle plugin or any other kind of code.
Thanks!