Maven structor - how shall i make this the right way? - maven-2

I am sitting with a problem on how to structor a maven project.
This is the structur on the project
So I am able to build every project like bbbbb/pom.xml and so on. Fx the bbbb/pom.xml has a parent that is in aaaaaa/parent/pom.xml. Then this has a parent in the root. But if I now want to build them all and add them all to a package how is that done?

Usual structure for nested maven projects would be:
/parent
pom.xml
/sub1
pom.xml
/sub2
pom.xml
...
Each pom in subX prohect references parent and parent pom lists SubX as modules. This way you should be able to build each subX project individually as well as everything from parent.
Not clear what you mean by 'add them all to a package'? Generally in maven there is 'one artifact per project' - so if you need say EAR you would create another subproject under same parent with packaging=ear. If you need 'all in one jar' you could look at maven-assembly-plugin, again in separate subproject perhaps.

Related

Mule ESB How to manage multiple project?

I have a base project named : ParentProject that contains all common businesses needed for children.
I also have 2 children Child1Project and Child2Project those project inherit all businesses of the ParentProject.
In the future, I may have Child3Project, Child4Project, so on.
So what should I do to organize those project in MULE ESB 3.7?
Many thanks.
One way to do this will be to make sure all your projects use Maven as build tool. Now, while creating the POM for the parent project, make sure it's packaging is "jar". Now, whenever you want too add this parent project properties to your child project, you'll just need to import the jar to the child project, or the repository configuration of the parent project in the POM of the child project.

maven release:perform and parent pom

I have a library which I "mavenized" recently and put into a local git repository.
In order to lock some plugin versions I created a simple parent pom which defines the plugin versions via pluginManagement (the parent pom file is not checked into any SCM repository). I specify the parent pom in my libraries pom file:
<parent>
<groupId>org.my.company</groupId>
<artifactId>superpom</artifactId>
<version>1</version>
</parent>
I use default directory structure.
When I try to perform a release using the release plugin I run into a problem.
mvn release:prepare runs fine however when I run mvn release:perform maven checks out the corresponding tag from my local git repository into the target/checkout folder and tries to run the deploy goal.
However the build fails with the error message that it can't find the parent pom file defined in my library pom file.
I assume that's related to the fact that maven tries to find the parent pom file in the target folder and it is not available there.
Is there an easy way how to solve this problem?
Update:
I have multiple unrelated GWT libraries which should share the common company parent pom file in order to specify plugin versions.
The parent pom is just used for defining some default versions and won't contain any module definitions because all GWT libraries are unrelated.
The GWT library are really simple and have no real dependencies to any other libraries apart from the default ones (gwt, junit)
Update2:
I solved the problem by installing the superpom into my local repository by running mvn install in the folder of my superpom.
The first fail you did is not to versionise the parent pom where you defined the pluginManagement area. This is the first step you must do put the pom.xml which you like to use a parent. Secondly you have to put the information about the VCS into the scm area of that pom. After you cleaned up everything you must do a mvn release:prepare release:perform of the parent pom. After that you are able to use it as a parent in your other projects. Furthermore you should define the distributionManagement area in your parent pom.

How can I validate the pluginManagement section of my parent POM in Maven?

I use a project layout like the first one described in the accepted answer to this question. If my parent-pom is managed, built and deployed separate from my project POMs, how can I ensure the pluginManagement section of my parent-pom is valid?
Maven only checks plugins that actually get used in the build as far as I can tell. Since most of the plugins I'm declaring in pluginManagement don't get used when I build the parent-pom, I have no way of knowing if I have an invalid entry until a child project tries to use a plugin it expects to be managed by the parent-pom.
I've tried the versions plugin, but it seems to ignore plugins that don't exist (ex: typos). I've tried declaring the plugins in my parent-pom with inherited=false, but then I have to tie every declared plugin to a phase. Plus, I don't necessarily want to run those plugins against my parent-pom.
I know lots of people use a parent-pom or a super-pom of some type, so there has to be something I'm overlooking.
In your parent pom module create a set of test maven projects, all inheriting parent pom, using some or all of the plugins defined there, and have parent pom run and verify build success of test maven projects. maven-invoker-plugin can help you in accomplishing all this. This plugin is used a lot for testing maven core plugins so you can find more usage examples in sources of maven core plugins.
Another advice is to add plugins to parent pom pluginManagement only when you need them, then you will have opportunity to test it as well. So steps are, start building a project which uses a given plugin not yet present in parent pom, add plugin to parent pom, release parent pom snapshot, make use of that snapshot in new project, if all OK release parent pom, and adjust reference to parent pom in new project. Later for another or same project if you need additional plugin or newer version of plugin already specified in parent pom, adjust parent pom, release new parent pom snapshot, check if it works for the given project, and if it does release parent pom, and adjust parent reference to newly released parent pom.

how to run only parent pom.xml in maven multi-module project

I have maven multi-modules project. At the parent level, i have some java files. And in the parent pom.xml, at the package phase i do some stuff.
Usually, when i run mvn package at parent level, the package phase of parent pom will be run and all the modules will be packaged as well.
I am looking for a way that allow me to do these (when i run mvn package):
allow me to run only paren pom.xml (the script at the package phase), not the modules. This is the 1st priority.
allow me to run paren pom.xml and some particular modules (like module 1, module 2 BUT not module 3 , module 4).
Can i use profile for those issue?
Thanks.
While I agree with the fact that you may not have optimal project structure, the answer is that Maven 2.2.1 has an option "--non-recursive" which satisfies your first requirement:
-N,--non-recursive Do not recurse into sub-projects
So something like this:
mvn --non-recursive clean compile
Why do you want to have java code on the top level? In my opinion this is not a very good idea. Have your code in the subprojects and let the top-level project be responsible for holding the general information and configuration of the entire project.
If you have some base-library code in the top-level project now, you can put it in a sub-project and set up dependencies between the projects.
Take a look at Maven parent pom vs modules pom
The nature of your question indicates that your project structure may not be optimal.

How to copy one Maven Pom.xml dependencies to other Pom.xml

Is there any way I can copy one pom.xml dependencies into other pom.xml
Update: Well, I have project A and Project B.
Project B is using some dependencies ( like Junit.jar, commons-httpclient, commons-collections, struts)
In the Project A : I would like to copy all project B dependencies in some out folder
This I can specify manually all dependencies jars of Project B in Project A but I would like to do automatically some script in Project A pom.xml.
Note: I don't want to build the project B in Project A pom.xml , I am building Project B separately
Does this make any sense?
If I understand well what you mean, keep only the dependencies in project B pom.xml. If you need something else in this pom, create another directory level B1, and push every other elements in it. Then makes B pom.xml a pom packaging with one module:B1.
Then you can make project B pom.xml the parent of project A pom.xml. A will inherit dependencies from B.
While I understand the spirit of the question (and only the spirit), the relation between project A and project B is still unclear so I'm not sure of the best way to implement this. Here are the options.
First solution: leverage transitive dependencies. There are some rules about them, but basically, if you declare a dependency on Project B in Project A, you'll get some of its dependencies transitively.
Second solution: use inheritance.
Third option: use another project of type pom to group the dependencies and declare a dependency on this pom.
I think the maven invoker plugin does pretty much exactly what you need:
http://maven.apache.org/plugins/maven-invoker-plugin/install-mojo.html
Or create a java class using the maven API, programmatically build a maven project and export the dependencies
start here:
http://maven.apache.org/ref/2.2.1/maven-project/apidocs
read a model:
http://maven.apache.org/ref/2.0.11/maven-model/apidocs/org/apache/maven/model/io/xpp3/MavenXpp3Reader.html
construct a MavenProject object using the model:
http://maven.apache.org/ref/2.2.1/maven-project/apidocs/org/apache/maven/project/MavenProject.html#MavenProject(org.apache.maven.model.Model%29
resolve and export the dependencies
Sean