简体   繁体   中英

Maven Assembly: Multiple pom Files/Different Builds

Our group has refactored out shared dependencies from three different projects to a new project, which is now the only dependency of the three projects. Instead of compiling these three projects with maven-assembly, we are using maven-jar. This results in a much smaller jar file, that can be deployed more quickly.

Now, for our Spring project, there are dependencies that are unique (spring-boot, mockito, etc.). We'd like to refactor these to the shared project, but would like to have separate builds of the shared project, one for the three projects that have shared dependencies, and one for the Spring project.

I thought creating a pom.spring.xml that was basically a copy of pom.xml plus the Spring dependencies would do the trick, but that didn't work. I see Maven has build profiles , but I do not see how to scope dependencies to different builds.

Any suggestions on how we might accomplish this, short of having two different shared projects?

Simple you should structure your product as follows

Project-Parent
  pom.xml - Shared parent pom. This pom declares the shared dependencies, and has project1, project2, and project2 as submodules.
  project1
    pom.xml - has the shared parent pom as its parent. 
  project2
    pom.xml - has the shared parent pom as its parent. 
  project3
    pom.xml - has the shared parent pom as its parent. 

SpringProject
  pom.xml - Spring project pom.  Has the shared parent pom as its parent.  Declares addition dependencies required for the spring project. 

This way project1, project2, and project3 are in the same build. SpringProject is in a separate build, but it inherits from the shared parent.

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