简体   繁体   中英

How can I use a Maven project as a dependency to another Maven project?

I'm new to Maven, therefore, sorry in advance if my question is too general. I have a Maven project, call it projectA , which resides in my company's Mercurial repository (let's call it https://hg.mycompany.com/niceprojects/ ). Recently, I built a separate Maven project, call it projectB in the same repository. I now want to use in projectB some classes that I have in projectA . The directory structure in the repository is currently:

-----niceprojects
       |
       |__projectA
       |     |__pom.xml
       |
       |__projectB
             |__pom.xml

What is a neat way of doing this? I would like to avoid manually building projectA , then adding its jars in projectB . I would also like to keep the same directory structure. Step-by-step instructions would be greatly appreciated. Many thanks!

A general advice when using Maven is to use a Maven Repository Manager such as Nexus.

In this case Nexus has the addtional benefit that it can host your jars.

So I advice to do the following:

  • Configure a CI (eg Jenkins) job to build projectA and deploy the JAR to your Nexus instance
  • Declare projectA as a dependency in projectB

When building projectB, it can download the projectA JAR from your Nexus instance without you having to build projectA yourself.

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