How to split a Maven multi-module build into multiple Jenkins build jobs? - maven

Let's consider a multi-module project which is composed of modules A, B, C, D, E. The dependencies among these are
C depends on B; B depends A
E depends on D; D depends B
I'd like to split this into two Jenkins builds
Build 1: Build C and its dependencies i.e. -pl :C -am
Copy Jenkins workspace
Build 2: Build E, D by utilizing the B.jar built by Build 1
I'm unable to figure out a way to tell Maven to do "Build 2". This is a simplified scenario but in my case there are several modules instead of just 5.

You may be able to use the -pl option to target a specific module. http://books.sonatype.com/mvnref-book/reference/_using_advanced_reactor_options.html.
Generally I don't see this done, though - if a project is multi-module, usually folks just invoke maven from the CI on the parent and let maven be responsible for building everything, as opposed to duplicating in the CI tool knowledge about dependencies/sub-components internal to the project that is already defined to maven. If there's a problem with a particular module building, Jenkins will still expose that in build log.

Related

Setting profile for dependency of multipart project command line

I have a multi-module project. Basically, I have a Project A, and Project B (An integration test). Project B relies on Project A to run. So when we run project B, we do something like: mvn clean package -B -pl :project-B -am. The -am part of the command instructs maven to also compile the dependency (Project A) and to include it. Problem is... When we run the dependency for project A, it doesn't seem to be pulling the correct profile. How do we set the profile to be used for compilation for dependency A in this command?
Thanks!

How can I simplify this maven multi-project (i.e., reactor) approach?

Suppose that I have many Github repos connected using a maven multi-module project (i.e., reactor), with a dependency tree like this...
A
B
C
D
F
G
...and a pom structure like this:
- <parent><version>1-SNAPSHOT...
GitHub repo A - pom.xml - <artifactId>A</artifactId><version>2-SNAPSHOT...
- <dependencies><X><version>3-SNAPSHOT...
- <modules><module>B</module></modules>
- <parent><version>1-SNAPSHOT...
GitHub repo B - pom.xml - <artifactId>B</artifactId><version>2-SNAPSHOT...
- <dependencies><Y><version>3-SNAPSHOT...
...
If somebody updates C (e.g., adds a new Java method) and does mvn deploy, I want to automatically (i.e., Continuous Integration (CI)) rebuild both A and B to use C's latest version. To successfully accomplish that, I can use the Jenkins Pipeline Maven Plugin (PMP), such that when somebody updates C, Jenkins then triggers a build for B, which finally triggers A--in that order. While building those repos, maven downloads the latest SNAPSHOT for C, B, and A using a private Maven repo.
Now suppose I have a new requirement: remove PMP.
Problem: By removing PMP, if somebody updates C, PMP will not rebuild A, so A can NOT automatically use it. But another requirement says that A must use the latest version of C.
Question: How can I solve or improve this?
If you always want to use the latest versions and rebuild everything, I would move all those git repos into one and use a multi-module project.

Maven "also-make"'s behavior

Let's suppose there are two projects, A and B, and B has a dependency on A.
Then I write
mvn verify --also-make --projects "B"
Maven help claims that also-make build projects required, so project A will be built.
But what does "build" mean? What maven phase will be applied to project A? Compile, verify or another?
It will apply the command or phase that you gave in the Maven command.

In a Multi-Module maven project, is it possible to have module B depend on a Plugin provided by Module A

I am trying to build a project containing multiple modules, one of which is a maven plugin which we use to generate sources further down the tree as such:
Module A: generator-plugin
Module B: uses generator-plugin
But when I try to build the parent project (doing a mvn clean deploy) during the clean phase, it tries to resolve the generator-plugin, which is obviously before it's built it.
Is there a way for this to be done without separating out the modules and building it first manually?
With Maven, I would suggest doing the most straightforward thing which would work and I think you know what that is--just make these two things separate Maven projects.

Can Maven automatically build a dependency that is not found?

I have three separate projects I am working on (A, B, and C).
Project B and C rely on a jar that project A generates.
Does Maven have the ability to automatically build project A if the dependency is not found?
The answers I've found so far are indicative of making the other 2 projects modules (which I believe to mean repository layout and incorporate them into project A) and create a parent / child pom.
A just plain "no" was also one of my conclusions as well.
It seems as though if I make a module of project A in B and C, maven doesn't really like that. Can Maven see projects during build time that are outside of the scope of the current project? Sorry if that's a little wordy.
The scenario works fine if A, B and C are modules of a common container project.
From root pom.xml:
<modules>
<module>project-a</module>
<module>project-b</module>
<module>project-c</module>
</modules>
where "project-a" etc. are names of maven project folders inside the parent folder.
The parent project must have <packaging>pom</packaging> for this to work.
Then you can build the parent project and it will build all children in order, or you can use one of the advanced Maven reactor flags.
e.g. mvn clean install -pl project-b will only build project B.
For more info, execute mvn --help and read the multi modules chapter from the Maven By Example book.
But to this question:
Does Maven have the ability to automatically build project A if the
dependency is not found?
... the answer is always no. Maven fails if the dependency is not found, but it never decides which projects to build. You are in charge of which projects need building.

Resources