maven - two different root poms

20,915

Solution 1

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

Solution 2

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.

Share:
20,915
Kevin Rave
Author by

Kevin Rave

Updated on August 18, 2020

Comments

  • Kevin Rave
    Kevin Rave almost 4 years

    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)?
  • Kevin Rave
    Kevin Rave almost 11 years
    Thanks, @Karthikeyan. It helps a lot. 2 things. 1.) I do not see .m2/settings.xml. 2.) When I package from the sub-module/project, its failing on dependencies. And when I package it from sub-module, does it automatically pull all dependencies from Parent?
  • Karthikeyan
    Karthikeyan almost 11 years
    @KevinRave I've updated my answer about settings.xml. For your 2nd question if the dependencies are not present in Central Repo it wont get download. Check which dependency is not getting downloaded if it's not developed by you then check which repository contains that artifact and configure it in settings.xml Settings Ref.
  • Kevin Rave
    Kevin Rave almost 11 years
    Awesome! Thanks! Here is what happened. I was running mvn package on the folder I was told to. It was missing dependencies on the other folder. So I went into that folder and ran mvn install, and then it asked for another folder dependency, I went into that and ran mvn install, and so on like 4 folders. I went into each folder and ran mvn install. Finally came back to original folder and ran mvn install. It worked. So my guess is root pom is not doing the job. Whats your take on this? Should I be running sonar_pom.xml as opposed to pom.xml as was told to me?
  • Karthikeyan
    Karthikeyan almost 11 years
    Typically if your dealing with multi-module project the parent pom should have those as modules, check this Multi module example for sample.