Avoid multiple upload of release artefact in nexus by Jenkins - maven

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

Related

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 pack too many jars to WEB-INF/lib, clear the local repository and re-execut mvn can make things right

In our company, thousands projects are build on 3 servers, with mvn commands.
A few projects occasionally pack too many jars to its WEB-INF/lib folder, the unwanted jars looks like another projects business code and its dependencies.
This is
the diff in WEB-INF/lib between right one(left) and too many jars one(right)
The jar in red frame looks like another project' jars, project name is "jd-common", and the other green jar on right is another project's dependencies.
This situation always reappeared until I clear local repository.
I guess the another project uses "mvn install" to install jars into local repository on build server, and our project is actually depend on jd-common-cached and jd-common-util only.
How can I avoid this?! Thanks for help.
First of all if the jars are there - you depend on them. You may depend on them implicitly (transitive dependencies). Run mvn dependency:tree to list all the dependencies (including transitive). You may find out that you depend on another project that in turn depends on those red/green jars.
Second, on the Build Server you don't want to share local repo with other projects. That's why, at least in Jenkins, there is an option Use Private Repository - this way all the project are going to be separated. This protects you from the situation when the artifact is not in remote repo anymore but the build is still green since that artifact is in local repo. But this has nothing to do with the problem you described.
It's finally be resolved!
The project A depend on a jar which deployed by another project B, the depend jar is a sub-module in B. (A->B)
Unfortunately:
1. A and B are packaged on the same build server
2. B's sub-module jar has the parent config in its pom.xml.
3. B use "mvn clean install -DskipTests" as the build command, so all the B's modules are installed in local repository.
Maven always package the local installed jar, and use the installed jar's pom file to find the sub dependencies, so when maven is executed, project A found that:"one of my depended jar has a parent, it's B, and all the B's sub-modules are found in local repository because of B installed all of them, I should package them all!".

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}

IntelliJ uses snapshots with timestamps instead of -SNAPSHOT to build artifact

I have a project with snapshot dependencies. For simplification let's say that there is an project A which depends on library B-0.1-SNAPSHOT.
A depends on B
B resides within Nexus repository as a snapshot. I can see that it is stored with timestamp so the actual name in Nexus is something like: B-0.1-20141126.171716-67.jar
After executing:
mvn clean install -U
on project A, dependency B is downloaded from Nexus to my local repository. There I can find two jars of library B:
B-0.1-SNAPSHOT.jar
B-0.1-20141126.171716-67.jar
So far so good.
After maven build is complete I can see that B-0.1-SNAPSHOT.jar was taken to build A artifact (.war file)
I also have project A imported to IntelliJ as a maven project. There I run it on Tomcat. Project is build by IntelliJ and B-0.1-20141126.171716-67.jar is added to .war file.
At the end I have .war with both B-0.1-SNAPSHOT.jar and B-0.1-20141126.171716-67.jar within WEB-INF/lib directory.
For me is seems like a bug in IntelliJ because B-0.1-SNAPSHOT.jar should be taken from local maven repository... not the timespamped version. Is there any way to force IntelliJ to act propeply?
Maven version is 3.2.3, IntelliJ 14.0.1 (but the same behavior was on 13).
I was faced to the same problem today, and I found how to disable this feature.
F4 on your module, and go to artifacts then select the name of your artifact webapp:exploded and check the show contents radio at the bottom of the frame.
Go to WEB-INF/lib and search for your dependecy B-0.1-SNAPSHOT.jar and expand the line you will see a compile output folder in it, just remove it, then repackage and run, you will now only have the B-0.1-SNAPSHOT.jar and the one with the timestamp should be gone.
The downside of this is that you will have to make sure to mvn install your B module before running the A module within IntelliJ, because IntelliJ won't package your dependency and bundle it with the code you've just edited but not installed in your local maven repository.

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