Question

Here is a my file system setup:

.m2/                 <--- Local Directory
app/
    pom.xml
    module1/
    module2/
    module3/
    target/          <--- Package directory

Question A

In the parent pom.xml, it has a dependency that all the modules depend upon. Though, when it goes into compile phase, module2 will need to depend on something that just compiled in module1 and module3 needs to depend on something in module2. How would you go about doing this without making two or three "maven projects"? Is it possible to run the compile, install, and package phases on each module individually one at a time (I'd rather do this solution)?

Question B

Also, I know when you install the module, all the "stuff" is updated and added to the local repo. When you are in the compile phase, by default, it grabs all the stuff it needs to depend on from the local repo (Correct if I'm wrong). Also, if I were able to achieve Question A, instead of using the local repo to obtain all the information needed for my dependencies, it possible use those same files from the packaged target directory instead?

Can these questions be answered by a simple pom manipulation and/or adding a plug-in? If this is possible, how would I go about doing this?

Was it helpful?

Solution

Maven is built with the idea of one project-one artifact. What you would normally do in the situation you describe is create a separate POM in each of the modules with the top level POM specified as the parent. Each of the sub modules would then inherit the dependencies of te parent and be free to add additional module specific dependencies. In the top level Pom, you then use the declaration to declare the three sub modules.

One key advantage is that if there are dependencies between the sub modules (like you describe), then maven will automatically figure out the correct order to build them in based in those dependencies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top