jenkins is not using local maven repository - maven

I have few jars which I have installed in my local maven repo(in windows under user/.m2). While building the project from command-line it's perfectly downloading the jars and packaging it.
Now I have created a Jenkins job (mvn clean package) to do so, but while running the jobs it's not picking up those jars from local repo instead trying to download it from central repo.
I tried all possible solutions available in Internet but still no luck. Can you please how I can configure Jenkins so that it should download those jars from my local repo ?
I also tried :-
1. offline mode
2. gave local repo path in settings.xml
3. use of nexus/artifactory in not an option for me

Seems maven executed by Jenkins not used the settings.xml in your local
you can try to change the maven command/goal in Jenkins job configuration with one more option:
-f <your local settings.xml path>
you can copy the settings.xml to your source code folder for debug purpose, after prove it work, then consider how to prepare the settings.xml for jenkins job with below options:
Option 1 use Config file provider plugin
Click Config Files -> Add a New Config -> Maven settings.xml
Change name and set your xml into content field:
In your job configuration, click the Advance... button in Build Section, choose your added settings.xml as below:

Related

Download Maven artifacts in Jenkins from another repo if one fails

In my Jenkins build I have a settings.xml file for pulling Maven dependencies. An artifact, if not found, should be downloaded from another Maven repo not specified in a settings file. Can this be done using code in Jenkinsfile? Any thought will be greatly appreciated.

Add custom, local project to integration-distribution

I am trying to add a custom project to the distribution. The project that I created via
mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller -DarchetypeArtifactId=opendaylight-startup-archetype -DarchetypeRepository=https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/ -DarchetypeCatalog=remote -DarchetypeVersion=1.6.0-SNAPSHOT
is (obviously) not available via the official nexus. I did not do any changes to this project.
I fired up karaf in distribution and tried to add the new project as a new repository via
feature:repo-add mvn:org.opendaylight.flowlistener/features-flowlistener/0.1.0-SNAPSHOT/xml/features
and received this error:
Adding feature url mvn:org.opendaylight.flowlistener/features-flowlistener/0.1.0-SNAPSHOT/xml/features
Error executing command: Error resolving artifact org.opendaylight.flowlistener:features-flowlistener:xml:features:0.1.0-SNAPSHOT: [Could not find artifact org.opendaylight.flowlistener:features-flowlistener:xml:features:0.1.0-SNAPSHOT in opendaylight-snapshot (https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/)] : mvn:org.opendaylight.flowlistener/features-flowlistener/0.1.0-SNAPSHOT/xml/features
Is it generally possible to add projects that only exist locally? What am I doing wrong?
Thanks in advance!
Max
Artifact repositories are configured using etc/org.ops4j.pax.url.mvn.cfg in Karaf. The configuration shipped in OpenDaylight only uses the Karaf system directory; it ignores the local Maven repository entirely.
To add your local Maven repository, you should edit the org.ops4j.pax.url.mvn.repositories entry at the end of the file to include your Maven repository:
org.ops4j.pax.url.mvn.repositories= \
file:${karaf.home}/${karaf.default.repository}#id=system.repository, \
file:${karaf.data}/kar#id=kar.repository#multi, \
file:${user.home}/.m2/repository#snapshots#id=m2.repository
By the way, unless you intend to contribute your project to OpenDaylight, you should avoid using the org.opendaylight namespace.
Karaf distribution uses the settings in etc/org.ops4j.pax.url.mvn.cfg to resolve maven artifacts. You will have to tweak these settings (e.g. maven local repo) for the distribution to find your local project. There is some in-line documentation on how to edit this file:
https://github.com/apache/karaf/blob/master/assemblies/features/base/src/main/resources/resources/etc/org.ops4j.pax.url.mvn.cfg

How to specify Maven local repository if I cannot use default Maven local repository settings?

we have restrictions on size of the $HOME and therefore I cannot use default settings ~/.m2/ We use in per-job configuration "use private maven repository" option. What to do if job 2 is dependent on an artifact produced by job 1.
If you're using maven directly (through commandline maybe) than create a settings.xml within the conf directory of your maven. This settings.xml should look like:
<settings>
<localRepository>C:\Repository</localRepository>
</settings>
If you're working with Eclipse than place the settings.xml wherever you want and go within Eclipse to Window -> Preferences -> Maven -> User Settings and set User Settings with the path to your settings.xml.
The simplest solution for the command line is to give it via command line:
mvn -Dmaven.repo.local=WhereEverYouLikeToHaveYourRepo

maven - how to deploy non-jar files

In my project I have many modules.
One of the modules requires a jar file to be deployed to the repository which it does fine.
The others involve every other kind of file: zip, kar etc.
I can see the zip get uploaded if I look for it via the terminal but if I browse Archiva it is not there.
The kar file, for example, does not need to be built but it's being worked on and is currently manually uploaded to the repository (Archiva). This is not desirable.
Each module has a POM and each POM uploads empty jar files to Archiva when it is built (with Jenkins). How can I avoid that? And can I copy files to Archiva without them having to be built into a jar file?
You can also give a try to "maven-deploy-plugin"
Invoke a maven target in jenkins with this plugin and provide the suitable parameters.
You would also need the repository to be added in you settings.xml if your repository requires login credentials and then use the ID, you mentioned in settings.xml, in the maven target.
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file
-Durl=<artifact-repo URL>
-Dfile=<name of the file>
-DgroupId=<Group Id>
-DartifactId=<Artifact Id>
-Dversion=<VERSION>
-Dpackaging=<packaging Type>
-DrepositoryId=<ID as mentioned in settings.xml>
Hope this may be of some help.

How do I run install4j in CloudBees using Maven?

I have Maven build projects in a local Hudson instance that I would like to port to CloudBees. Install4j runs as an executable on the host system. In my experience, this includes an installer and registering the license key via the install4j UI.
How do I configure install4j so that I can run this build in the headless CloudBees environment?
I have been able to set this up, and it is very straight-forward.
1. Upload install4j to CloudBees
CloudBees runs on Linux, so extract and upload the Linux TAR.GZ version of install4j to your private repository.
HINT: via FTP => https://{username}#repository-{account}.forge.cloudbees.com/private
This directory is accessible from all build projects via the path: /private/{account}
2. Update Maven settings.xml
If you don't already have one, you'll need to create a settings.xml file in the same private repository.
Further reading on how to create a settings.xml: How do I deploy to private Maven repo from CloudBees?
You'll need to add the "install4j.home" and "install4j.licenseKey" properties to a profile in your settings.xml file according to the Sonatype Documentation*.
HINT: "install4j.home" is something like "/private/{account}/install4j5"
3. Update project pom.xml
Again, following the Sonatype Documentation*, update your project's pom.xml with the necessary build steps.
* Sonatype Documentation
http://sonatype.github.com/install4j-support/install4j-maven-plugin/

Resources