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

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.

Related

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

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.

Building multimodule maven project

Hi I've searched the net, read a bunch of articles, so questions and documentation but I can not find solution, here is my problem.
I have a multimodule maven project which contains three modules A,B and C.
A and B independent and C is depend on A and B, and of course I have a parent project. I also have a jenkins server set up to build these projects, and a nexus repository.
My problem is that when I build the project the maven builds A and B correctly but for C it downloads an older artifact from the nexus repository and of course it fails to build module C.
How can I make the maven to use the currently built jars which installed into the local repository instead of the older ones on nexus?
Version of A and B and C set to 1.1.{build_number}-SNAPSHOT with maven version plugin, and as I understand maven should use the newer from local but it does not do it.
Initially I do not want to post hundreds of lines of pom.xmls but if you need section I will provide it.
Any help would be appreciated. Thank You!
I have been setting the version numbers in the submodule's poms and changed to inherit version number from parent pom. In module C's pom module A and B versions set to ${project.version}

Avoid multiple upload of release artefact in nexus by Jenkins

I have a web project split in multiple maven artefacts.
Let say it is :
A, a jar
B, a jar
C, a jar
D, a war
So, D has a dependency on B and C. B has a dependency on A.
Those modules versions are not always synchroneous.
A can be on version 3-SNAPSHOT while B is still in version 5 with a dependency on A version 2.
I configured jenkins to cascade build B when A is built, D when B or C is built.
Those modules also get rebuilt when a change is detected in the git repository.
Artefacts are automatically deployed in nexus repository by a post-build action.
So, if I push in git a new version 3-SNAPSHOT of A, a 3-SNAPSHOT jar is built and pushed in nexus. But, because of Jenkins dependency, a new build of B version 2 (release version) is triggered. The build itself goes ok, but the deploy to nexus fails, as I do not allow redeploy of release artefacts.
How can I avoid this situation ? Not trying to upload to nexus when the artefact has a release version and this version already exists in nexus would be acceptable.
I am using Jenkins 1.480 and maven 3.0.4.
You can trigger parameterized build with https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin and add a parameter to job B.
Conditional build plugin might also help https://wiki.jenkins-ci.org/display/JENKINS/Conditional+BuildStep+Plugin

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.

Build a maven product with components from a different git repository

Our project has two different git repositories A and B. Both A and B are multi module projects. B's code is finally built as a eclipse product using maven parent pom. B requires a component/ feature from A which needs to be included in the eclipse product. How can I achieve this functionality. Do I need to publish the results of A's build to a webserver, so that B can access it as a repository? or can I include A as dependency to B's build so that B can package this component in the final product? Where/ how can I specify this configuration?
Let me know if any other information is required.
Thanks in Advance!
This should be possible on your local machine if you run 'mvn install' on project A. If you want the artifact from project A to be available to other developers you need to setup a maven repository such as Archiva and run 'mvn deploy' instead
You should at least deploy project A to the local repository (mvn install). Then it will be available to project B through maven.

Resources