maven build multiple rpms basing on multimodule project - maven

I'm trying to set up maven to build my project in the specific way. I have the following structure:
pom.xml
module1
pom.xml
module2
pom.xml
module2.1
pom.xml
module2.2
pom.xml
module2.3
pom.xml
I actually want to build separate rpms based on module1, module2.2 and module2.3 and want all these rpms be included into root one. Could, please, anybody help me with that if there is any ways to do this using maven and it's plugin only. Also I want this to be done via profiles, if it's possible. All my tryings led me to nothing.
Thanks in advance!

It looks like you need the maven-assembly-plugin. You should use it and define <moduleSets/> in your assembly descriptor.

Related

Why there is a pom.xml for all jars in mave repository

In the maven repository, there is a pom.xml corresponding to every jar. What is the use of that pom.xml.
How important is that pom.xml and will the execution work without that pom.xml ? Thanks in advance.
Each of those jars is a project (somewhere) that was built using Maven - hence the need for a pom. Also, the pom describes all the transitive dependencies for any jar that your project needs. Those files are important, and your project cannot build without them.

Artifactory, Maven and a project with several modules

I have a Maven project with several modules, with a structure similar to:
project
module-1
pom.xml
module-2
pom.xml
..
module-N
pom.xml
pom.xml
I have defined the Artifactory Maven plugin in the parent pom.xml which is under project, like it is done in the examples they offer on their website and I've also tried the example they have in git.
My problem is that I don't want to publish to Artifactory all the artifacts generated by the parent pom, but only those under certain modules, so I tried defining the plugin in the parent pom with the tag <publishArtifacts>false</publishArtifacts> and then defining the plugin again on the modules which contain artifacts I really do want to deploy with <publishArtifacts>true</publishArtifacts>, however no artifact is deployed.
If I try the other way, only specifying I do not want to publish Artifacts on the modules I don't, it does deploy all ignoring that configuration.
How should this be done using this plugin?
You can use the publisher\excludePatterns in the artifactory plugin section of the pom.xml to exclude artifacts from being published.
you can declare multiple patterns with wildcards, and separate each with a comma.
For example, if you are using the sample from
"https://github.com/JFrogDev/project-examples/tree/master/artifactory-maven-plugin-example"
then, setting you're pom with
<excludePatterns>multi3*.war,multi2*.jar</excludePatterns>
would exclude those files from being published to Artifactory.
hope that helps...

How to run maven plugin for only root of multimodule project [duplicate]

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.

What are the difference between pom.xml and effective pom in Apache Maven?

Could somebody explain to me, what are are differences between the file pom.xml and the file effective pom.xml in an apache maven project?
The Super POM
All Maven project POMs extend the Super POM, which defines a set of defaults shared by all projects.
The Simplest POM
All Maven POMs inherit defaults from the Super POM. If you are just writing a simple project that produces a JAR from some source in src/main/java, want to run your JUnit tests in src/test/java, and want to build a project site using mvn site, you don’t have to customize anything. All you would need, in this case, is the simplest possible POM shown in The Simplest POM. This POM defines a groupId, artifactId, and version: the three required coordinates for every project.
The Effective POM
It is the merge between The Super POM and the POM from The Simplest POM.
NOTE: This info was extracted from the following link (in the link the explanation is very complete)
Maven: The Complete Reference - 3.2. The POM
You can see the difference of a pom.xml and the effective pom.xml using
mvn help:effective-pom
which is describe here.
In a multi module project you'll use a parent pom.xml for defining general settings for all modules and then in each module there will only be specific settings.
The above goal will help you analyze the resulting pom that you could of course actually use instead of the parent reference.
The whole idea is by using the generalization (super-pom) / specialization (module pom) approach there is a central place where you can specify the general configuration. This is much more efficient then having to cut&paste the general parts.
Please also note that the effective pom will add the default behavior e.g. for the jar plugin so that you can debug issues like
Maven JAR Plugin 3.0.2 Error: You have to use a classifier to attach supplemental artifacts to the project instead of replacing them
with this approach. See also Maven `help:effective-pom` only generating for a single project, not all projects

maven project dependency is a generated jar (not in maven repo)

I am a maven newbie. My project depends on another maven project (ProjectA) in that I need to run mvn clean package on ProjectA which gives me JarA.
Then, I need to run java JarA feeding it with an xml configuration file which gives me another JarB. I need both JarA and JarB as dependencies on my project (ProjectB).
Any comments on whether it is possible to achieve these steps in projectB's pom file? Would having parent-submodule type of a configuration help? Thanks!
Maybe. The most simple solution to get JarB would be to add a unit test to project A. But that doesn't tell Maven about this JAR, so it will ignore it.
The next step would be to get the test to write JarB as JarA-config into the target/ folder of project A. Maven supports multiple artifacts as "build results". You can then use the "qualifier" to distinguish between them.
Use build-helper:attach-artifact to tell Maven about the second JAR. See "Attach additional artifacts to your project" for an example.
Note that package happens after test, so your test case can create the second JAR and build-helper will then find it.
In project B, you can then use this to depend on both JARs
<dependency>
<groupId>x</groupId>
<artifactId>jarA</artifactId>
</dependency>
<dependency>
<groupId>x</groupId>
<artifactId>jarA</artifactId>
<classifier>config</classifier>
</dependency>
Note the additional <classifier> element.
Note: For this to work, you need to run mvn install in project A.

Resources