This is one of those “I had to figure out how to do this today, so the next time I google this, I have a place to look” blog posts. Today, I had to upload a zip file as a build artifact to our Nexus 3 repository. The zip file had been generated by custom shell scripts that did not have a Maven, Ivy or Gradle projects to wrap them.
The obvious way to do this seemed like using the Nexus 3 REST API, invoked like this:
curl -v -u <username>:<password> \
--upload-file artifact.zip \
https://<nexus-server>/repository/maven-releases/com/example/artifact/1.0.0/artifact-1.0.0.zip
This works and the file is available in the repository. However, this method has the following shortcomings:
- There will not be a
POM
file generated for this artifact. - The maven metadata associated with this artifact will not be updated.
Using Maven Deploy Plugin’s deploy file mojo in this situation will help us satisfy the above requirements. The mojo is capable of running in arbitrary directories without the need for a pom.xml
to be present. However, it does expect you to specify authentication parameters in a settings.xml
file. In my situation, I did not want to write credentials in a settings.xml
, so I had to improvise.
This is what I ended up using and it works like a charm:
mvn deploy:deploy-file \
-DgroupId=com.example \
-DartifactId=artifact \
-Dversion=1.0.0 \
-Dpackaging=zip \
-Dfile=artifact.zip \
-DgeneratePom=true \
-DupdateReleaseInfo=true \
-Durl="https://${NEXUS_USERNAME}:${NEXUS_PASSWORD}@<nexus-server>/repository/maven-releases/"
If you have questions or comments about this blog post, you can get in touch with me on Twitter @sdqali.
If you liked this post, you'll also like...
- Formatting Java Instant for resolutions
- FreeBuilder plugin for IntelliJ
- A Jackson and FreeBuilder quirk
- Implementing feature toggles for a Spring Boot application - Part 4
- Implementing feature toggles for a Spring Boot application - Part 3
- Implementing feature toggles for a Spring Boot application - Part 2
- Implementing feature toggles for a Spring Boot application - Part 1
- A very basic introduction to deploying a Java application using Kubernetes
- Handling Deserialization errors in Spring Redis Sessions
- Controlling Redis auto-configuration for Spring Boot Session
- JWT authentication with Spring Web - Part 5
- JWT authentication with Spring Web - Part 4
- JWT authentication with Spring Web - Part 3
- JWT authentication with Spring Web - Part 2
- JWT authentication with Spring Web - Part 1
- JSON logging for Spring applications
- Injecting dependencies into a Spring @Configuration
- Filtering responses in Spring MVC
- Deprecating domain events in Axon
- Programmable exit codes for spring command line applications - 2
- Programmable exit codes for Spring command line applications
- Using custom arguments in Spring MVC controllers
- Authentication for Apache Camel HTTP components
- Integration testing Spring command line applications
- Integration testing challenges for non-web Spring applications
- Implementing custom annotations for Spring MVC
- Validating RequestParams and PathVariables in Spring MVC
- Testing async responses using MockMvc
- Running multiple applications in the same Tomcat installation
- A simple JMeter test with login
- Java Arrays in JRuby