I have been searching for a while now and could not find any working solution or guide/tutorial for releasing Maven modules when using nested Git submodules.
We have a complex structure of public and private projects that require a specific order to build successfully. Our goal is to perform a Maven release in order to tag and deploy multiple Maven artifacts in a single step.
Here is the simplified Maven project/modules and Git repository structure:
parent-public:1.0.0:pom (descriptor only, no Maven modules, public Git repository)
| |
| |- public-module:1.0.0-SNAPSHOT:jar
| (Maven module, child of parent-public, Git submodule, public repository)
|
|- parent-private:1.0.0-SNAPSHOT:pom
(Maven modules, Git submodule, private repository)
|
|- public-module:1.0.0-SNAPSHOT:jar
| (Maven module only, child of parent-public, Git submodule, public repository, released)
|
|- private-module:1.0.0-SNAPSHOT:war
(Maven module, child of parent-private, released)
The current structure allows Maven to build and deploy projects/modules independently.
When releasing public-module
(from the parent-public/parent-private/public-module directory), the maven-release-plugin
performs well (Git repository has been tagged and release artifact has been deployed).
When releasing parent-private
, the maven-release-plugin
prepares and starts performing the release before failing during the target checkout (this problem is discussed here, but solution is not working in my context and not enough reputation to comment).
Here is the current maven-release-plugin
configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<tagNameFormat>v@{project.version}</tagNameFormat>
<commitByProject>true</commitByProject>
<pushChanges>true</pushChanges>
</configuration>
</plugin>
Is there a more elegant way to organize Maven modules and Git repositories in order to release multiple Maven artifacts? Alternatively, did someone find a solution to clone recursively Git submodules during checkout just before deploying artifacts?
In most cases, Git submodules are used when your project becomes more complex, and while your project depends on the main Git repository, you might want to keep their change history separate. Using the above as an example, the Room repository depends on the House repository, but they operate separately.
Use the git submodule update command to set the submodules to the commit specified by the main repository. This means that if you pull in new changes into the submodules, you need to create a new commit in your main repository in order to track the updates of the nested submodules.
The list of steps required to clone a Git repository with submodules is: Issue a git clone command on the parent repository. Issue a git submodule init command. Issue a git submodule update command.
Git submodules allow you to keep a git repository as a subdirectory of another git repository. Git submodules are simply a reference to another repository at a particular snapshot in time. Git submodules enable a Git repository to incorporate and track version history of external code.
The answer to this question isn't going to satisfy the initial question, but the Maven Release plugin isn't smart enough to understand git submodule boundaries. I think what you are looking for is the ability for the Maven Release plugin to sense that a directory points to a submodule and for this release plugin to automatically tag across boundaries? This won't happen, and I don't think it is on anyone's plan at this point.
What I always recommend for Maven users who use Git is never break the boundaries of a multi-module project that needs to use the Release plugin across submodules. Keep it confined to a single repository.
Again, this isn't a great answer, but having used the Maven Release Plugin for many years, it is also true that it isn't a great plugin :-(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With