Maven2 - Deploy only master pom - maven

I have a master POM which has many modules defined in it.
I want to make some minor changes to the master POM and deploy the new Master POM to our nexus instance.
Everything is confgured ok to allow this, but when I do a mvn clean install deploy all the modules are built and deployed too. I dont want this.
How do I tell maven to just deploy the master POM and not build/deploy the modules? Can this be done?

Use this option:
-N,--non-recursive Do not recurse into sub-projects
Reference: http://maven.apache.org/guides/mini/guide-multiple-modules.html

Related

Jenkins pipeline - maven installing dependency projects

I am setting up a CI/CD with the following components:
-Bitbucket
-Jenkins
-Docker
-Maven
The desired flow:
Committing code to Bitbucket
Webhook Jenkins on changes
Jenkins pipeline does the following:
mvn install 2 projects, SDK+API
takes the API jar and build image
pushes image to repository
deploys service or container to docker
Where I am currently stuck is the following:
I have a PROJECT-A, that has multiple dependency projects that has to be maven installed, before maven installing PROJECT-A and creating an image of it.
Could anybody advise on what is the best practice here?
I have googled an it's say that my only feasible and maintainable option should be using Parent POM. However I failed to understand how do I do that.
<modules>
<module>project1</module>
<module>project2</module>
<module>project3</module>
</modules>
Even if your project would be structured differently with parent pom, where would those additional projects come from? In general mvn install does something different then you mean in this question -
install: install the package into the local repository, for use as a dependency in other projects locally
The best practice here (and missing element) is a package repository. For example your private artifactory or nexus. You would mvn install all the packages to it and maven would automatically resolve the dependencies from it basing on its POM and appropriate configuration.

Installation and deployment of maven test-jar

I've discovered the wonderful test-jar facility in Maven: https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html
But it may so happen that one project needs to use the test-jar of another project. From https://stackoverflow.com/a/6469256/421049 and experimentation, it would seem that using mvn install does not install the test-jar to the local ~/.m2/repository. So how does one project on my machine use the test jars of another project not in the same aggregate POM?
Yet it would seem from Maven deploy not to upload test jar that deployment of a project to Maven Central does in fact deploy the test-jar? So I can deploy it to Nexus but not install it locally? And if I deploy it to Nexus, will my local project using a dependency of <type>test-jar</type> go find it on Maven Central?
It turns out that maven-jar-plugin does in fact install the test-jar (e.g. foo-1.2.3-tests.jar) in the local Maven repository ~/.m2/repository/.... Wonderful!
My problem is that I had inadvertently configured the maven-jar-plugin to be in a separate profile named release. (I had copied and pasted to the wrong location in my POM.) That's why the test-jar didn't show up in my local repository after a mvn install, and that's why it suddenly showed up later (after I used -P release once in testing), and I thought I had just missed it when I looked the first time.
I move the maven-jar-plugin to the <build> section and everything is working fine: the test-jar gets put into the local maven repository using mvn install.
In my case, I was setting maven.test.skip for a particular build profile. That property actually causes tests to not be compiled/installed, thus also preventing their deploy. The solution was to set the skipTests property instead.

Maven multimodule build. I want to deploy the ear to our Repository, but not the other modules

We have multi-module project that consists of 17 modules. There'a base jar module. There are 15 filter jar modules that depend upon that base jar. Then, there's the Ear that we build that contains the 16 other jars.
We have the build working just fine, but we'd like to deploy our Ear to our Maven repository -- mainly because it'll make it easy for our deployment tools to get to it. Plus, we can easily do that via mvn deploy without having to put together another tool.
The problem is that when we say mvn deploy, we deploy the Ear and the 16 other jars. Those jars are not used in any other project, and we simply don't want them clogging up our Maven repository.
Is there a way to specify that a particular module doesn't get put into the Maven repository when I say mvn deploy?
Looking through the documentation, I found the ${maven.skip.deploy} property. I actually set this to true in the parent project, then set it to false in the EAR build. That does what I want, deploys only the EAR. This way, if another module is added, it will by default not be deployed.
steve c recommended mvn -pl core-ear clean deploy which doesn't work in my circumstance. The module I want to deploy is actually a module of a module, so the main level build doesn't see it.
Our structure is like this:
parent --|
|-engine
|-filter1
|-filter2
.
.
|-distribution --|
|--jar
|--sar
|--ear <-Deploying this one only
khmarbaise mentioned setting <skip>true</skip> in all of the modules except for the one I want to deploy. khmarbaise recommends against this, and I don't blame him. However, there are several issues here. First, we're doing continuous delivery which means that we will have a new version in our repository for each build. I also want to make sure no one tries to depend upon these jars.
I set the property ${maven.deploy.skip} to false in my parent module. This means it's that way in all of my modules and none of them will deploy. I don't need to configure my maven-deploy-plugin in order to set this.
I then set ${maven.deploy.skip} to true in the only module I actually want to deploy (which is the ear module of the distribution submodule). Running mvn clean deploy from the parent now only deploys the ear distribution module I actually want to deploy.

How to do remove a projects artifacts from the local maven repo?

When running mvn install on a local multi module project it builds and install the projects artifacts into the local repo. mvn clean seems to clean up my project specific target directories.
What command do I use with maven to get it to uninstall my projects modules from the local repo? for example my projects outputs foo-0.1.jar and bar-0.2.jar I want those removed from my local repo without having to go in there and delete them myself.
mvn build-helper:remove-project-artifact
You can purge artifacts from your local repository, but why do you like to do this? Apart from that you can do that via maven-dependency-plugin:
This will purge all project- and dependency artifacts
mvn dependency:purge-local-repository -DreResolve=false
This can be influenced by supplemental command line arguments (see the documentation) for further details.
Best is to implement a release strategy, i.e. as long as the artifacts under development appending the version with SNAPSHOT. Maven then automatically updates the artifacts in the local repository when you run install. Once you have completed the development you remove the SNAPSHOT and release the version (i.e. via deploy). If further development is required you could increase the version number and append it again with SNAPSHOT.

Share Maven Dependencies with team members using Mercurial

I want to share all the External Jars currently being managed by MAVEN with my other team members. I am using Mercurial as my SCM and i am trying to figure what is the easiest way to commit my entire project (include libs) to a repository so that my team members can clone and get running without severe eclipse configuration?
Maven is there in order to help you retrieving libraries. So that, all you have to do is to commit all your files including the pom.xml (.hg should contains everything in target, and other unrelevant files)
Then your project members can pull the sources and run mvn eclipse:eclipse (see eclipse & maven.
And finally import the project in Eclipse.
That was is they need sources...
If they only need the jars, you must put in your infrastructure a company repo that will handle your deployment using mvn deploy. Some information there maven repo::Intro, take special care at the wagon you could use (ftp, ...)
This way, when you're done with your devel and you have pushed your code, you just have to deploy the jar on your repo.
Doing so, your project member'll have to run mvn -U eclipse:eclipse or any goal to update their local repository with your lastest deployed version.

Resources