Publish Jar
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.
For a Java application with Docker, see the Gradle or Maven example.
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 package
creates a jar file of the library. It also runs unit tests.mvn upload
uploads 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
Create a new pipeline in Codefresh and define as parameters your Nexus credentials. You could also use shared configuration or any other credential mechanism you already use in your other pipelines.
Then copy/paste the Codefresh YAML file in the pipeline editor. Here are the full contents of the file:
codefresh.yml
The pipeline starts by checking out the code using a git clone step. The next step is a freestyle one and packages the jar file. We also use the Codefresh volume for caching.
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.password
and 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.
Related articles
Gradle example
Spring boot example
Codefresh YAML for pipeline definitions
Steps in pipelines
Creating pipelines
How Codefresh pipelines work