Running Jenkins Job using only the local repository - maven

I have a Spring boot project on my local machine and I am using personal dependencies in the project. When I run mvn clean package on the windows terminal it works but when I use mvn clean package in the Jenkins Job it does try to download dependencies in the remote repository. My question is how to force Jenkins to use my local repository without looking the remote one.

You should able to use maven option mvn -o or mvn -llr.
But that assumes ~/ is the same user Jenkins agent ia running on.
Your better bet is to use mvn install:install-file to install the jars locally.
You can set up your job to do a curl.or wget step to retrieve the files from "somewhere", then have your pom call a pom which installs the jars locally from workapce to repo, then does your build.
That makes your job portable and still pulls the rest of OSS jars from Central, without needed an intermediary remote.

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.

Jenkins CI server and Nexus Server on the same Box

I am in a situation where I have one Build Server box which is to carry out all continuous integration and manage our maven repository. The box works as follows:
There is one maven repository which is hosted through Apache Server as a URL for developers to use
All Jenkins jobs (including release jobs) run mvn install so that artifacts are kept in this one repository.
I would like to get rid of the Apache server and run Nexus on this same box to manage and host repositories, however I have the following questions/ideas:
With Nexus and Jenkins on the same box, will it mean that I will have to manage two repositories, one where maven installs an artifact to a local repository, and one where maven deploys an artifact to nexus? Would it be possible to have Nexus manage the "mvn install" repository also? How can I make sure we don't run out of disk space on the server very very quickly all the time?
Thanks
Added as response to comments: Thank you both, I am thinking I will just set the Jenkins jobs and release plugin goals to mvn package deploy:deploy in order to skip the install phase, that way, artifacts go directly from the target directory to Nexus. However I guess the Jenkins job will require a local repository from which to use depedencies which will get copied from Nexus to the maven local repository during the build, I am not sure if this can be avoided though.
mvn install installs in the local repository
mvn deploy installs to the remote repository
these semantics are defined in the lifecycle and map to different plugins. Their implementations are different.
You don't have to manage the local repository. Actually for some if not most jobs you might even want to define it localized to the job (with the 'Use private Maven repository' option) instead of to the user who is running the job, especially that you plan to use nexus for repository.
You will have to change your jobs to use mvn deploy instead.
How can I make sure we don't run out of disk space on the server very
very quickly all the time?
Configure Jenkins/Nexus. Discard old builds and disable automatic artifact archiving. Both settings can be found in the Jenkins job-configuration. Also you could delete old artifacts automatically from Nexus using Scheduling Tasks.
There is no need to install the artifacts into the local maven repository when using Jenkins/Nexus on a dedicated server.

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.

Maven - Install an artifact to the Nexus repository

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.

Maven without Internet connection

I'm new to maven project.
I'm changing an ant project to maven project.
To install the 3rd party jar's in maven local repository, I used install command.
Its trying to download the resource jar.pom.
I don't have download access in my organization so the build failed for installtion.
After request i got the resouce jar and clean jar in my desktop(also i can get other necessary jar).
How to make maven to use these jar for the process and how to install the jar in local repository without internet acess.
I downloaded the jar and placed in local repository but it couldn't point the path and use those jars.
please let me know what steps i have follow to run maven install and other commands to build the project without internet access.
where should i placed the jar which i have downloaded by external way.
Please guide me for building and deploying the project.
Thanks in advance.
http://maven.40175.n5.nabble.com/Maven-installation-and-using-in-project-without-Internet-conncetion-tp4564443p4564443.html.
http://www.coderanch.com/t/544641/Jobs-Offered/careers/Maven-installation-project-without-Internet#2471141
I've posted same question in these link
You need an internet connection. Maven isn't initially self-sufficient. It needs to download a bunch of plugins along with their dependencies and the dependencies of your own project. And this really depends on what sort of settings you have for your projects. One set up will require one set of dependencies, another - a whole different one. You can't download artifacts from the Maven Central manually and then install them locally one by one. Simply put, that sounds stupid.
I understand that you're coming from the Ant world where Ant has everything it needs on the local file system. However, Maven relies on the fact that it will have a central repository (either Maven Central, or your own repository - Nexus, Artifactory, etc.) from which to download the plugins and dependencies it needs. There is no point in you migrating to Maven, unless you'll be allowed access to the Central Maven Repository.
Yes, indeed, you can run Maven offline and you can have Maven produce a local repository for you to use when you are in offline mode. However, what you're trying to do is against Maven's principles.
If your company won't allow access to Maven Central, just stick to Ant. Your effort will be a waste of your company's and, ultimately, your own time.
In fact the maven strenght is mainly in the internet accessible repositories and automatic dependency management. But it's possible to use this tool to build your project if you have all dependencies required for your project in your local repository. Then you may use -o option for offline mode and maven will not try to download updated artefact versions.
To get the artifacts into you local repository you have several options:
1) connect to the internet once and mvn build the project (this will download all required dependencies)
2) install dependencies as jar to the local repository manualy (using appropriate mvn command)
I think the questioner is looking for -o or --offline option for mvn. This is a command line option and can be provided while executing.
I think you can setup your repo correctly and execute the mvn goals once when you are connected to internet and use the -o option for later executions .
Hope this helps.
~Abhay
You can configure maven to run in offline mode. Add this entry to your settings.xml
<offline>true</offline>
See here for further information:
http://maven.apache.org/settings.html
Before you can use offline mode, you have to install all necessary third party jars to your local maven repository.
mvn install:install-file
-Dfile=filename.jar
-DgroupId=com.stackoverflow
-DartifactId=artifact
-Dversion=1.0.0
-Dpackaging=jar
-DcreateChecksum=true
-DgeneratePom=true
It's much easier to get those jars in your local repository using an internet connection and online mode.
It's possible to install these resource jars in your local maven repo using install-file. This will make the available to the build. You'll have to do this for each individually, but once that's done you won't have to do anything special.
To be clear, maven puts everything in your local repository, both the jar you're building with this project and the various library jars. Because your system cannot be connected to the internet to maven can populate the local repo with your libraries, you'll have to use this manual approach.
Edit: You should be able to run install-file anywhere. When you do, you'll need to provide the groupId, artifactId, version, and packaging using the command line options. If you already have a POM file for the library, you can provide that instead via -DpomFile=your-pom.xml.
This question has some useful info: How to manually install an artifact in Maven 2?

Resources