I've a multi-module maven application that we need build through Jenkins.
Project structure is like:
a.xml
<artifactId>parent-1</artifactId>
<modules>
<module>lookup-1</module>
<module>lookup-2</module>
</modules>
lookup-1.xml
<artifactId>lookup-1</artifactId>
<parent>
<groupId>com.lookup</groupId>
<artifactId>parent-1</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<name>lookup-1</name>
lookup-2.xml
<artifactId>lookup-2</artifactId>
<parent>
<groupId>com.lookup</groupId>
<artifactId>parent-1</artifactId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<name>lookup-2</name>
now,
mvn clean install -f a.xml works fine. For this I created one Jenkins job.
Now, same as a.xml, I've another project with b.xml. b.xml has the same code as of a.xml except different Ids. So, I've created another jenkins job for b.xml.
Both jobs work fine. But, now I want to build both these project from single Jenkins job based on which project we commit in Git. For, this I want to have a new project(pom.xml) and where I want to put both a and b under modules tag. Like this:
pom.xml
<name>combined_project</name>
<artifactId>combined_project</artifactId>
<modules>
<module>a</module>
<module>b</module>
</modules>
a.xml
<artifactId>parent-1</artifactId>
<name>a</name>
<parent>
<artifactId>combined_project</artifactId>
</parent>
<modules>
<module>lookup-1</module>
<module>lookup-2</module>
</modules>
But, its not working for me. I'm getting following exception in maven:
Child module D:\....\a of D:\....\pom.xml does not exist
Maven not able to find child module.
I've following project structure:
project
|_ lookup-1
|_ lookup-1.xml
|_ lookup-2
|_ lookup-2.xml
|_ a.xml
|_ b.xml
|_ pom.xml
Any hint?
a.xml has 2 sub modules lookup-1 and lookup-2. By default maven is looking for the sub modules in the nested maps. So you need to have the following directory structure:
<parent>
|
+- a/pom.xml
| |
| +- lookup-1/pom.xml
| |
| +- lookup-2/pom.xml
|
+- b/pom.xml
|
+- pom.xml
Alternative is to change the parent into
<name>combined_project</name>
<artifactId>combined_project</artifactId>
<modules>
<module>a</module>
<module>b</module>
<module>lookup-1</module>
<module>lookup-2</module>
</modules>
Maven follows a project structure and each <module> will contain a pom.xml file. As you have explicitly stated the pom file in command line that file will be selected as the pom.xml for that project. However, for every submodule that is listed maven will search for the exact file named "pom.xml" for each submodule.
From the folder structure provided, it can be inferred that a.xml can act as a pom file when explicitly specified in command-line but it cannot act as a module as it does not have a dedicated folder with pom.xml.
A maven project in general has the following structure:
archetype-id(folder)
pom.xml(packaging: pom)(with one module module-artifact-id)
module-artifact-id(folder)
pom.xml
If you are attempting to build only the module that has been updated then the module that is not checked in recently will not be part of the newly created archive. But if you still would want to do it for some "special" reason. The following method might be the one you are looking for:
(I wouldn't recommend it -- as it is messy and goes against conventions)
Have two sub-modules in a single project and also Have two .xml files (pom files to be specified in commandline). In one xml file lets say "a.xml" "module-1" is to be specified as a module and in "b.xml" "module-2" is to be specified as a module.
Using the currently modified module invoke the build on that pom file. Example, if module-1 is modified specify a.xml in the command line as the pom.xml.
Please note that I have not attempted it but if it is possible this is one of the ways I can think of by which we can accomplish what you are looking for.
Reference for passing parameters : Pass a dynamic parameter in Jenkins build
Two possibilities :
Either you need to fix the path of your submodules in the modules section of the parent pom.
While creating a jenkins job you will have to tell jenkins to clone submodules as well. when I started with jenkins, I faced similar problem. The solution was to enable "Recursively update submodules" checkbox under Advanced scm behaviors in Jenkins UI.
Related
Given the following minimal Maven multi-module structure. Module A is released together with the project and the other modules of the project. However, it inherits from some other parent POM (rather than the project POM).
|--------------------|
|-------------| | module A that does |
| project POM |--- module --->| *not* inherit from |
|-------------| | project POM |
|--------------------|
How can I propagate or synchronize properties from project POM to module A?
Project
<project>
<parent>some-parent</parent>
<groupId>some-group</groupId>
<artifactId>my-project</artifactId>
<properties>
<revision>1.0.0-SNAPSHOT</revision>
</properties>
<modules>
<module>A</module> <!-- NOT inheriting from here -->
<module>B</module> <!-- inheriting from here -->
</modules>
</project>
Module
<project>
<parent>some-OTHER-parent</parent>
<!-- don't want to duplicate this, should be propagated from my-project -->
<!--properties>
<revision>1.0.0-SNAPSHOT</revision>
</properties-->
<groupId>some-group</groupId>
<artifactId>A</artifactId>
</project>
First attempt
I wrote a small Groovy script for the GMavenPlus plugin that updates the module A pom.xml correctly synchronizing the project properties. However, even though the plugin runs in the validate phase (i.e. the earliest possible) it's too late. Maven already initialized the reactor with the old properties.
I want to give developers the convenience of simply running mvn some-task without having to worry about the properties being consistent. Managing those manually would be a pain.
8< ---------------
off-topic: the complete use case
I have a project ("my-project") that contains code other projects will consume: libraries, tools, utilities, etc (modules "B", "B+", "B++"). Furthermore, it contains a POM module (module "A") that said business projects will inherit from. That POM represents an opinionated blue-print that those projects should adhere to unless there are good reasons not to.
I need the project POM "my-project" to build all the modules "B", "B+", "B++".
The POM module "A"
has definitions very different from "my-project" as itself serves as a parent for the business projects.
(amongst others) lists all the modules "B", "B+", "B++", etc. in its dependency management section.
has to be released together with all the "B"s it manages -> that's why it lives in the same code project
shares a few external dependencies "X", "Y", "Z" with the project POM "my-project"
=> I need the versions for "X", "Y", "Z" in both the project POM "my-project" and in the POM module "A"
We are using a parent pom that has a child module where we have 2 pom files - the one named pom.xml and other being images-pom.xml.
This is the situation because we are doing some naming changes and for the time being we want to have them both.
In our parent pom we have the following code
<modules>
<module>child</module>
</modules>
<packaging>pom</packaging>
By default it seems that this is looking and trying to build the pom.xml - but in reality we want to use the images-pom.xml Is there any way to achieve this without creating a new module and using profiles?
I am working on a generator project, which is split up in multiple maven sub-projects:
root
|pom.xml
|target/
|
+module1
| |pom.xml
| |target/
|
+module2
|pom.xml
The root pom is of packaging type "pom".
Module1 will now use
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
to do a exec:java on a dependency jar that will generate some code to the relative path "target/generated-sources/..."
My problem is now that when doing a mvn clean install from within module1 everything works fine and the result is in "root/module1/target".
But when starting from the root directory with mvn clean install - then the code will be generated to root/target and will not be compiled/packaged by the module1 pom.xml - the result here is an empty jar.
So I assume that the work directory is different when starting from within the module or from the root.
How can I achieve that both kinds of start (from root or module1) will work with the same result? - i.e. how to achieve that the work directory is always there where the actual executing pom.mxl is?
I have my project structure like this.
pro
pro-common
pom.xml
pro-list-history ==> [1] Packaging type pom
pro-list-main
pro-list-entities
pom.xml
pro-list-daos
pom.xml
pro-list-services
pom.xml
pom.xml
pro-search
pom.xml
pro-customers
pom.xml
pom.xml
pro2
pro-list-history
pro-list-main
pro-list-entities
pom.xml
pro-list-daos
pom.xml
pro-list-services
pom.xml ==> Want to use [1]
pom.xml
pom.xml
My question is is okay to use groupId and artifactID from [1] in the second project as shown above?
The referred module packaging type is pom.
Put a dependency section in the project two at the specified module as shown above, and specified as pom. Build is fine, but its not importing the dependencies from that project.
Can anyone help?
First, you can depend on a POM dependency. See: Netbeans: maven dependencies of type pom for an example and discussion.
However, I think you are asking if there is a short-hand way to import all the sub-modules of a "parent" module by specifying its pom.If so, see this question:
Maven - include all submodules of a pom as dependencies in another module
You can just reference the sub-module in another module like you would a file:
<modules>
<module>inside-project-module</module>
<module>inside-project-module</module>
<module>inside-project-module</module>
<module>../OtherProject/outside-project-module</module>
<modules>
I am using maven-gae-plugin from http://code.google.com/p/maven-gae-plugin/ to create a multi-module project using inheritance (parent-project reference)
The structure that I have is as below:
|
`-- pom.xml
|-- base-api-project (packaging=jar)
| `-- pom.xml
|-- main-www-project (packaging=war)
| `-- pom.xml
The root pom.xml is configured as parent + aggregator (with reference to the modules).
When I build using the root pom.xml, everything is compiled and packaged great.
However, when I run mvn gae:run in the main-www-project folder, I get an error that the base-api-project is not found in the registered repositories. I scans all registered repositories...
But my question is... if it's already there in ~/.m2/repository, then why should I hunt across the net?
I there something wrong that I'm doing?
When using snapshot versions maven will always look for the latest snapshot, whereas releases will be resolved locally first.
However, each artifact in the local repo will also need the corresponding POM, and that POM may declare dependencies that are not in the local repo, or are snapshot versions (etc. recursively).