I’ve been looking into multi-module projects in Maven, and I can only find examples of modules existing as subdirectories to a parent project. Would I be mistaken in deducing from this that there’s no way to share a module between two maven projects without having to package it up and deploy it to a repository? That would strike me as needlessly cumbersome.
For example, say I’m actively working on two related projects that don’t talk to each other except through an API bridge I’m working on that I plan to use for future things. The bridge is constantly updating as work on the two projects progress.
So, if I want to leverage Maven modules for this effort, one project pom.xml would look like this…
<groupId>net.syndog</groupId>
<artifactId>myproject</artifactId>
.
.
.
<modules>
<module>myproject-bridge</module>
</modules>
…and another looks like this…
<groupId>net.syndog</groupId>
<artifactId>myotherproject</artifactId>
.
.
.
<modules>
<module>myproject-bridge</module>
</modules>
Assuming modules in Maven must be subdirectories of the projects in which they’re a part of, how can myproject and myotherproject both use the myproject-bridge module at once?
Is this even possible with Maven, or do I have to package and deploy myproject-bridge to a repo every time I make a tweak to it? Perhaps I’m mistaken, but this seems like it would be such a commonplace issue, but no one seems to be talking about it. Am I going about this all wrong?
The usual way of using such a dependency is to define a dependency which results in this:
but the result of this approach is that you need to have a separate project which contains exactly this api. This can be simplified by using a IDE which solves the dependencies between the projects via the workspaces instead of the repository. Otherwise you need to do regularly a mvn install (if you are working locally only) or mvn deploy (via repository manager).
The other solution would be to use a real multi-module project which would look like this:
where project-a and project-b using the myproject-bridge via a simple dependency. In the root you define the modules (as you mentioned) via
and in myproject-a you simply define
and in myproject-b the same way.
You must be aware that using a module does not necessarily means to define a dependency. This gives you also the opportunity to use the myproject-bridge from a complete different project either after release or as SNAPSHOT.