简体   繁体   中英

How can I keep two Maven projects loosely coupled?

I have Maven Project A which depends on Maven Project B. These are maintained by me in a GitHub repository. Project B is a utility project that will be used by many other projects. Project A is an application that makes use of the utilities in Project B. My Maven projects do not exist in any public repository and are currently under development.
Now, I want another person to integrate with my Project A. I cannot just package my projects and send them over, because they will be changing constantly. He/she will have to checkout my code within his/her build environment and integrate my parts to his/her application, also pulling changes from my repo regularly.
The point here is that I want both projects to go hand-in-hand. After googling around, I ended up with these two solutions:
1) Make them both siblings of the same parent project. This approach has the advantage that the integrator will always take all dependencies when checking out the parent project. However, this solution tights the two projects together forever. Project B is a utility project that will be used by other projects which do not care about Project A.
2) "Manually" instruct the integrator to checkout both projects and handle the dependency on his/her end, eg by installing the projects to his/her local Maven repo or having the IDE resolve workspace dependencies. This way though I have to manually tell the dependency to the integrator and he/she will have to remember to re-install updated versions to the local repo.

Would there be any other strategy to have the integrator take all dependencies in an automated way and be able to automatically build my code without manual intervention? Another requirement is that Project B will not be tightly coupled to Project A so it can be used freely by other projects in the future.

Some things that come to my mind have to do with different structure on the Maven dependency scheme or perhaps a Continuous Integration component that comes in place to support the procedure. I do not however have a clear strategy on how I could go on with this, or if it is even possible... Any clues?

If your project is open source, you could use this process: http://central.sonatype.org/pages/ossrh-guide.html to avoid having to host your own Maven repo.

Your other option would be to stand up your own Nexus/Maven repository and have the projects that depend on your artifacts configure another repository in their settings.xml file so they could check for snapshot deployments in your Nexus repo. You would deploy snapshots as necessary to your Maven repository.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM