Configure maven registry in .m2 - java

I would like to use the gitlab package registry globally.
My situation is as follows:
I' working on several maven projects for which I use a nexus server for my packages.
In my team, we would like to get rid of this nexus server because of maintenance effort in some migrations.
I recently found the gitlab package registry tool which works well so far when we want to push our packages.
Now we have the want to configure a settings.xml in our .m2 folder so that the dependencies are getting fetched from gitlab ci globally.
Is there please a way to do that? So far we just found the possibility with applying the parameter -s to the mvn command line which does not fit to our processes.
A template of a settings.xml would be appreciated.
Thanks in advance.

Related

Adding local jar (oracle driver) to Maven and Bamboo

I need to use the oracle database driver (oracle.jdbc.driver.OracleDriver) for a project but Oracle does not have a Maven repository for it, so the only way that I have found is to download it onto my machine and then "install" the .jar to Maven as seen in this article.
However, now it is time to add the project to my work's Bamboo build server, but of course the build fails because it can't find the oracle driver.
My question is: how is this sort of thing generally handled? There doesn't seem to be a way to "add" a .jar to a Bamboo build and then point Maven on Bamboo to that .jar. Another alternative that I'm trying is putting the oracle .jar on an internal git repository but I don't know how to point Maven to pull a .jar from a git repository (my current understanding is that maven repos and git repos are different thing entirely).
Any tips or suggestions appreciated, thank you.
The usual way is to set up a Nexus/Artifactory on a server. This server is used for the built artifacts (your Bamboo deploys the EARs/WARs/JARs to it), to proxy external repositories (not necessary, but will speed up things) and to manage third party jars that are not available elsewhere.
In your settings.xml you just point to this Nexus/Artifactory and do the same for the Bamboo.

How to share a maven archetype via email to be used in Eclipse?

I have an eclipse maven-based proyect that I want to share as an example of use of a big library. I have downloaded and installed maven, created an archetype from the proyect (mvn archetype:create-from-project), installed it in my local repository (mvn install) and tested it (archetype:generate -DarchetypeCatalog=local).
Now, I want to share the archetype with a few people. I want to send them a file/files that they can add directly to their eclipse environment to create new proyects using my archetype, but I can't find a way. I don't want to set up a remote repository.
Thanks in advance.
Follow this URL is has all the steps to host your archtype to the central repository. Once it is on the central repository, it can be used by any user in their project.
https://maven.apache.org/guides/mini/guide-central-repository-upload.html
I just realized that Maven is a solution to a much bigger task and was never designed for the way I intended to use it.
Maven depends on servers for distribution of artifacts (an archetype is just one kind of artifact) and sending them by email wasn't a planned use case.

Upload Jenkins build file .war to Nexus Repository remotely

I have Jenkins setup with Maven as a build tool. Java project is pulled from SVN and it is built using Maven (all inside Jenkins). Once the project is built I get project.war package file which I need to be uploaded to Nexus Repository.
Whats the simplest way to do that?
I tried tweaking/modifying my existing settings.xml and pom.xml, but no luck. Nothing is happening.
I want the .war file to be uploaded to Nexus Repository which I configured on other box.
You can use the Nexus Maven Plugin for your purpose. And in your Jenkins script, just run:
mvn clean deploy
As it is described in the documentation.
I tried mvn deploy, mvn clean deploy but neither work.. "mvn" dont work (May be I need to set environment variable or something.. help me ! with that too ! :))
Somehow it worked fine now. I am using the Goal as : clean deploy it worked for me. Also, when I used below in pom.xml file :-
release and then snapshot
It didn't worked.
However, I have created new repo in nexus and provided its path. It worked fine. Jenkins was able to upload my .war file to Nexus repo.
Now Next I have to do is,
As many build my jenkin produces and push to Nexus. Nexus should version it for me.. Any idea would be really appreciated

How to configure maven without internet access

While converting dynamic web project into maven project I'm getting this error:
"CoreException: Could not calculate build plan:
Plugin org.apache.maven.plugins:maven-compiler-plugin"
I can't access the internet to download any jars and plugins while converting because I'm on a restricted network with no internet access. Is there is any way to make a Maven project with no internet access?
I'm using:
Eclipse kepler
Maven 3.0.4
JDK 1.6
You can manually download or some how find required artifacts.(jars) Then copy them into your local maven repository.
Now you can use
mvn clean install -o // off-line build
to build your project without internet.
About half year ago, when I worked as an intern in a company, we also encountered with virtually the same problem as you ------ we were in the restricted network, and our computers couldn't access the internet, but we still needed to use maven to update the project dependencies. Here is our solution:
Find a server that can access the internet, and also you can access
the server in your restricted network.
Establish a sonatype nexus server on the server you found above.
The sonatype nexus serer is just a private repository in your environment. You can upload your own packages into the repository, and also the nexus server can download required packages from the central maven repository.
The last thing you need to do is to change the repository address in your pom.xml to the nexus server address
Hopefully, this can help you. And if you have any questions, please feel free to ask me again.
mvn clean -o install
Running in Offline Mode
If you ever need to use Maven without having access to a network, you should use the following option to prevent any attempt to check for updates to plugins or dependencies over a network:
-o, --offline
When running with the offline option enabled, Maven will not attempt to connect to a remote repository to retrieve artifacts.
refer here and here for more options
I think without internet you can not download it, initially you need an internet connection because maven need bunch of dependency and it all depend on your project. if you download them manually one by one there is some chance that you could miss some dependency and error will resolve one by one it will take more time and research to search dependency over internet and fix them one by one.
so I prefer instead of downloading manually go for internet connection it will download all the dependency automatically.
if you have restricted access download it at home and replace that folder with your work area folder
Maven is a dependency management system which downloads the required dependencies from the internet or a mirror of the central maven repository. Incase you do not have both - connection to internet (Central Maven Repository) or a local mirror (Nexus is the most used replicator of the central maven repository in a Enterprise setting) - then maven is bound to get the dependencies off your local hard disk from the .m2 folder under your logged in user directory.
Hence, in order for maven to work, manually register all dependencies which you have listed in the pom(s) as described in the maven guide :
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
You can try copying your .m2 folder to the machine without internet... and then running maven offline.

Travis CI not using extra Maven repository provided in pom.xml

I have a Java-based GitHub project, fitnessjiffy-spring (I'm currently focused on the "bootstrap" branch). It depends on a library built from another GitHib project, fitnessjiff-etl. I am trying to configure both of these to be built by Travis CI.
Unfortunately, Travis is not as sophisticated as Jenkins or Hudson in dealing with Maven-based Java projects. Jenkins can easily handle dependencies between projects, but the same concept doesn't seem to exist with Travis. If one project depends on another, then that other project must already be built previously... and its artifact uploaded to some Maven repo where the first project can download it later.
My "fitnessjiffy-etl" library is building and deploying just fine. I'm using Bintray for Maven repository hosting, and you can clearly see my artifacts over plain HTTP at:
http://dl.bintray.com/steve-perkins/maven/
In my "fitnessjiffy-spring" project, I am adding this Maven repo location directly in the pom.xml, so that Travis will be able to find that artifact dependency. Here is the state of my POM at the time of this writing. Note the <repositories> element at the bottom of the file.
When I build this project locally, it works just fine. I can see it downloading the Maven artifact from "http://dl.bintray.com/...". However, when I try to build on Travis CI it fails every time. I can see in the console log that Travis is still trying to download the artifact from Maven Central rather than my specified repo.
Does this make sense to anyone else? Why does Maven utilize a custom repository location in a POM file when building locally, but ignores this configuration when running on a Travis CI build?
From digging into this further, I discovered that Travis uses its own proxy for Maven Central, and has configured Maven to force ALL dependency requests through their proxy. In other words, it does not seem possible at this time to use additional Maven repos specified in the POM file of a project built on Travis.
In my case, I ended up refactoring such that project would not need the outside JAR dependency. I also switched to Drone.io, so I could manage my settings on the build server rather than having to carry a YAML file in my repository (which always struck me as a bit daft).
However, even on Drone it's still a major hassle to manage dependencies between multiple projects (extremely common with Java development). For Java, I just don't think there's currently an adequate substitute for Jenkins or Hudson, maybe running on a cheap Digital Ocean droplet or some other VPS provider instance.
In your install phase add a $HOME/.m2/settings.xml define your custom repository.
cache:
directories:
- "$HOME/.m2"
install:
- curl -o $HOME/.m2/settings.xml
https://raw.githubusercontent.com/trajano/trajano/master/src/site/resources/settings.xml
- mvn dependency:go-offline
script:
- mvn clean install site

Categories

Resources