How to upload a JAR file to Nexus or artifactory
Even though Codefresh has great support for containers, it can still be used for traditional JAR uploads of libraries or applications that are not dockerized yet. In this example we will compile a JAR and upload it to Nexus. The process is the same for Artifactory or any other package manager.
The example Java library project
You can see the example project at https://github.com/codefresh-contrib/plain-jar-sample-lib. The repository contains a simple Java library built with Maven with the following goals:
mvn packagecreates a jar file of the library. It also runs unit tests.
mvn uploaduploads the jar to a package manager such as Nexus or Artifactory.
We use Nexus for this example. To upload the Jar manually first edit the
pom.xml with the URL of the package manager. The project also includes a settings.xml with parameterized credential.
From your workstation you can upload the jar manually with:
mvn -s settings.xml -Dserver.password=my-nexus-user -Dserver.username=my-nexus-pass deploy
If you then visit Nexus you should see your JAR file in the snapshots repository.
Create a CI pipeline for publishing a JAR file
Then copy/paste the Codefresh YAML file in the pipeline editor. Here are the full contents of the file:
You can define the version of Maven/JDK you want to use by picking the appropriate image from Dockerhub, or using any of your own images (even from external registries).
Note the use of the two user-defined environment variables passed to
server.username. You will need to define those yourself. See the documentation on User Procided Variables.
Once the pipeline has finished you should see the JAR file in the Nexus browser UI.
You can use the same pipeline for Artifactory or any other compliant Java package registry.