Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven - two different root poms

I am new to Maven. I am given a new project and that has the following structure.

Data_Res
  |
  ---res-search
  |     |
  |     -----res-hast
  |     |       |
  |     |       ------src/main....
  |     |       |
  |     |       ------pom.xml
  |     -----res-haster
  |     |       |
  |     |       ------src/main....
  |     |       |
  |     |       ------pom.xml
  |     |
  |     ----pom.xml
  | 
  |
  ---pom.xml
  ---sonar_pom.xml

I don't see modules section in root pom.xml. But I do see modules section in sonar_pom.xml. It does not include all child nodes. Can a folder/project have two poms? Or can we execute them separately?

  1. How do I interpret this one? Sub-modules or individual projects? Are there any metrics to find out?
  2. I was told to run mvn clean install on root pom. I did that. I was asked to verify if all dependencies for one of the sub-folders are provided. How to check these? I can see some files under .m2 folder in my home directory.
  3. How do I build/package this? I am going to be working on one of the sub-folders. Not sur e if its a separate project or sub-module. In that case, can I directly go to that folder and run mvn package / build from that folder (pom.xml exists)?
like image 673
Kevin Rave Avatar asked May 27 '13 05:05

Kevin Rave


2 Answers

When you execute a goal (e.g mvn install) maven will check for pom.xml on the folder of the execution if pom.xml present it will perform the goal for that folder (i.e project) if there are any modules mentioned the same goal will be executed on the modules, this operation is recursive.

Can a folder/project have two poms?

Yes you can have multiple poms for a project, but the default is pom.xml if you want to use alternate pom file you can use -f to mention the alternate pom file in your case mvn -f sonar_pom.xml clean install, probaly that pom file is used for sonar.

How do I interpret this one? Sub-modules or individual projects? Are there any metrics to find out?

Every project has a pom.xml can be build independently if the parent and all dependecies are present in your local maven repo.

I was told to run mvn clean install on root pom. I did that. I was asked to verify if all dependencies for one of the sub-folders are provided. How to check these? I can see some files under .m2 folder in my home directory.

To verify the dependency check your local maven repo the default is ~/.m2/repository, but the settings can be changed in settings.xml. Check ~/.m2/settings.xml if the file doesn't exists you can find the global settings in <maven_home>/conf/settings.xml copy it to ~/.m2/ then it can be overridden check the following tag <localRepository>/path/to/local/repo</localRepository>

How do I build/package this? I am going to be working on one of the sub-folders. Not sur e if its a separate project or sub-module. In that case, can I directly go to that folder and run mvn package / build from that folder (pom.xml exists)?

As I mentioned earlier you can do mvn package on your module if you have the parent and all dependencies. You can get these in combination of two ways

  1. Install those in your system using mvn install or
  2. using remote repositories
like image 126
Karthikeyan Vaithilingam Avatar answered Oct 08 '22 04:10

Karthikeyan Vaithilingam


Just to add to the already correct answer: in eclipse I had to create a new "run configuration" under the "Maven Build" run configs. I set the base directory to the standard

${project_loc:connect}

and the "Goals" field to

-f pom_deploy.xml install -T 1C

Then I could right-click on the custom pom_deploy.xml --> run as... --> run configurations --> Custom Maven Deploy

The '-T 1C' is optional and tells Maven to use multiple processors simultaneously for the build/compile process.

like image 45
Kurt Avatar answered Oct 08 '22 06:10

Kurt