Multi Module Maven Parent POM - maven

There are multiple modules in my application . All of them are maven projects .
So I am working on creating a parent pom for all these projects and was able to create one and ran maven build on this parent pom and works fine build
But when I opened the project in eclipse , the parent pom was not included in the projects displayed so it was picking it up for the build process to take place . My project structure is as follows
ProjectA
|
--------subProjects
ProjectB
|
--------subprojects
ProjectC
|
--------subProjects
ProjectD
|
-------subprojects
Pom.xml
So what do I need to make an eclipse recognise this parent pom ? I created another maven module and made it parent pom . But is there any way i could avoid creating another project and achieve the above scenario ?

One thing you can do is to import the global structure as a maven project on its own and then import the subprojects one by one as maven project in eclipse.

you can use mvn eclipse:eclipse in the command line for all the project one by one, and then you can select by importing(Maven Project Type) all the maven projects if you select the directory on the top of your maven projects.
In this case you make all settings in the pom and no additional configs in eclipse.

Related

Combining multiple maven projects into a single repository in IntelliJ

I am having some standalone maven build and sbt built projects in scala.
These projects are now in different repositories in github.
Now I am trying to keep all these projects in a single repository as different projects.
As the first step I created pom file from all the sbt build projects.
Now i created a new repository and added all these projects as separate modules, each one are having their own pom.xml.
I have a common pom.xml as parent.
I have to implement all the dependencies which are common in the parent pom.xml(how can I use dependencyManagement here)
Each project module should create their own jar file after packaging.
Any leads appreciated!

How to copy all the dependencies in Maven project modules to a directory?

I have a big local maven project that contains multiple modules which are inturn maven projects and are dependent on one another.
Ex.
parent pom.xml
<pom>
<module1> #jar
<module2> #dependent_on_module1.jar
<module3> #
</pom>
I have mentioned the sequence to build those modules in the parent pom.xml .
I also mentioned where to place the artifacts when they're built in groudId and artifactId.
But in the dependencies for all those modules, I have mentioned a common local system path for all those modules.
Is there any way to copy all the artifacts which are being created for modules when maven build is performed on the parent pom to a specific directory that can be dynamically mentioned when the maven command is run.
I have searched for maven copy command. But looks like it's not going to do what I want.
Any suggestions?

Create a maven project with parent's packaging war

I want to create a Maven project. I want it to have a parent project. The problem is that the parent project has a package in: war.
I see an error :
Invalid packaging for parent POM must be "pom" but is "war"
What should I do ?
A parent project (packaging with type pom) is by definition a container of submodules. Only the submodules are allowed to be of specific packaging types (like war or jar). You use a parent project to aggregate common dependencies and build configurations.
I suggest that you put the code you want to reuse in a submodule of type jar and then add this submodule as a dependency of other projects you have (with packaing type war or jar).
You could read Chapter 6 of the book Maven by Example where it illustrates how to build a maven multi-module project.

how to run only specific maven module

how to run only specific maven module from maven eclipse project.
I have few modules in my EAR maven project and when I build whole project it fails at one module WAR,saying this war artifact module not found in repository.
Your multi module project must e having a common parent. First install that parent pom in your local repository. Now go to child module project and maven build the project.
It should work given that all its dependencies are present.

Maven project structure

In svn repository I have a folder 'product' under which are all my Eclipse plugins and features, parallel to these there is parent POM. This setup works well when I build in Jenkins, I just check out 'product' and install pom.xml. However, I can't figure out how this setup works in Eclipse workspace? I can't check out pom.xml by itself into workspace, and if I do I need to check it out as single file under a project which brakes path to parent POM. How should I check out and build in such setup?
Also, do I need to define relativePath of parent POM in my plugins? I found that if I omit it, then I get error about path being missing.
Just to summarize, my svn repository structure is this:
repo/
trunk/
product <- maven project (folder with .project set as maven nature)
pluginA
pluginB
featureA
pom.xml
.project
I think you have two options:
Deploy your parent POM to a locally available repository, perhaps your company Nexus server, for example? This will then be available to all products and for all your colleagues.
Restructure your project to look more Maven-like, e.g.
|-- plugin1
|-- pom.xml
|-- ....
|-- plugin2...
|-- feature1...
|-- ...
pom.xml <-- parent POM
This second option may be better in the long term, otherwise your Jenkins server relies on you remembering to locally install the updated parent POM, rather than just plucking it from svn.
If you use m2eclipse (e.g. available from the Juno site), you can import any Maven project structure into Eclipse. In your case, the product folder would be imported as an Eclipse project, as well as the individual features and bundles.
<relativePath> defaults to .., so you need to specify it if the parent POM is not in the parent folder. You can set it to undefined (e.g. through an empty <relativePath/> tag) if the parent POM is not available locally. In this case, Maven will always resolve the parent POM from the local Maven repository or the configured remote (Maven) repositories.

Resources