Maven - Install an artifact to the Nexus repository - maven

I have a problem currently when i run the command mvn install, the artifact is installed in my local repository (i.e. in %HOME/.m2 folder) but not in the Nexus repository.
I know with Nexus i can add an artifact manually using the GUI but is there a way to do install the artifact as part of the mvn command?

What you're seeing is normal behavior in the standard maven lifecycle. The install phase is only supposed to install the artifact locally. You need to run deploy, which comes after install. That's when maven uploads artifacts to a remote repository. The remote repo for deployment is configured in the distribution management section of the pom.

Related

What is the difference between deploying an artifact into Artifactory with 'mvn deploy' command and with Artifactory UI?

I usually use mvn versions:use-latest-versions command to update my dependencies to the latest ones which other teams have been deployed to our free Jfrog's Artifactory server on our local address : http://192.168.100.243:8082/artifactory/X_Douran/.
My problem is when I deploy an artifact (a jar file) with Artifactory UI or with curl (using Jfrog's Rest Api), the command mvn versions:use-latest-versions doesn't work correctly and do not update my pom but when I run mvn clean deploy on my source code of my dependent project then running mvn versions:use-latest-versions on my final project it works correctly and do update my dependency in my pom.
So I want to know what is the different between deploying via Artifactory UI and deploying via mvn clean deploy ?
You always need to deploy the POM along the JAR, otherwise Maven will not work correctly with these dependencies. Furthermore, you need to make sure that the metadata files are updated. I am not sure that Artifactory does this if you deploy using curl or the UI.
Deploying your own JARs regularly through the UI is not recommended. You should build them on a build server (like Jenkins) and then automatically deploy them to Artifactory.
Changing JAR files "by hand" should be forbidden.

Integrate the local maven plugin with remote repository

I have created a simple maven plugin and installed it in my local repo(.m2). Now I want to use that plugin with a git repo(maven project). How can I do that?
Currently, I am trying to build my git repo using Jenkins and it throws below error-
[ERROR] Plugin sample.plugin:hello-maven-plugin:0.0.1-SNAPSHOT or one of its dependencies could not be resolved: Could not find artifact sample.plugin:hello-maven-plugin:jar:0.0.1-SNAPSHOT
I believe simply changing the pom file of my git repo won't work. What should I do so that it resolves the plugin dependency by looking into the .m2 dir first
Your Jenkins probably deploys to a Nexus or Artifactory server. That server is also the right place to manage your plugin.

Configure nexus repository to only store jars that are installed (selected by me)

I would like to configure a nexus repository to only manage jars that I install. Right now it also retrieves jars from maven central and stores them in the repository. I don't want that to happen.
Can anyone point me in the right direction how this can be achieved?
When you say to store the "jars that are installed" , if you are referring to the artifacts being created by your project, you can have a hosted maven repository snapshot/release and use maven deploy plugin to upload it on to your nexus repository.
You can either create a profile in your pom and activate in your install it on mvn install phase to upload the artifacts to your nexus repository.

How to configure maven to copy dependencies from central repo to local repository mirror (not local repo)

All
Need to get maven to copy central dependencies to local filesystem repository mirror. Can't work out how to do this in maven (3.3.1).
We have:
[1] maven central, which for the UK is: "http://uk.maven.org/maven2"
[2] local remote filesystem repository mirror: "c:/mylocalRepository"
[3] local repo "c:/users/myuser/.m2/repository"
Version of maven is 3.3.1 (doing a migration from 2.0.10).
We need to run our system without connecting to central (behind firewalls) and also without using a repository manager (Nexus, Archiva or the like) - it's something we would like to change but cannot change our infrastructure immediately. Please don't reply just saying do this.
Therefore we need our dependencies in a local file system that maven will then be use as a mirror of central.
I can't find a way to configure maven to build this - I'm getting dependencies - jar + pom and then using
To install jars:
mvn org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file
-Durl="file:///{repositoryPath}"
-DrepositoryId="InternalRepo"
-Dfile="{jarFile}"
-DpomFile="{pomFile}"
-DrepositoryLayout=default
-DgroupId={groupId}
-DartifactId={artifactId}
-Dversion={version}
-Dpackaging=jar
-s "C:/apache-maven-3.3.1/conf/settings_centralRepo.xml"
To install Poms:
mvn org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file
-Durl="file:///{repositoryPath}"
-DrepositoryId="InternalRepo"
-Dfile="{pomFile}"
-DpomFile="{pomFile}"
-DrepositoryLayout=default
-DgroupId={groupId}
-DartifactId={artifactId}
-Dversion={version}
-Dpackaging=pom
-s "C:/apache-maven-3.3.1/conf/settings_centralRepo.xml"
Ideally would like a configuration that we could put in the parent pom that would trigger all dependencies to be copied over. However the documentation implies this is for build artifacts rather than dependencies. There's usually a way in maven, but it can be hard to find.
Any help much appreciated - I've currently jury-rigged a script to do this and it tedious and labour intensive.

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.

Resources