never deploy non-java artifacts with maven

Maven is a build system and a de facto standard of the Java world. It solves the problem of dependencies resolution and improve the previous tool ant which doesn't offer a standardized way of building. Despite Maven is clearly not designed to deploy non-java artifacts, people can try to do it. It usually occured in a large-scale project where developpers have no system background, and they try to answer to system problems with their everyday tool. I will explain here why you should never do this.

Upload to archive repository

We will consider here the situation where we have a custom RPM of vim and we want to upload it to an artifact repository: Nexus. Like artifactory Nexus a very common binary repository manager that supports many types of repositories and especially maven repositories. You can query it using an REST API or using maven command: mvn.

upload with curl

Here is the command that I use to upload non-java artifact. In case of error nexus will answer with an HTTP header containing a string describing the problem. It is easy to use and easy to troobleshoot.

curl -v --upload-file vim-enhanced-7.4.873-2.el7.psychotic.x86_64.rpm.html -u foo:bar http://localhost:8081/repository/MyRpms/vim-enhanced-7.4.873-2.el7.psychotic.x86_64.rpm.html

This the way I recommand to upload on nexus.

upload artifact with maven-deploy-file

Here is the way to do the same thing wih maven. Maven uses plugin to do everything, it is a plugin execution framework. To deploy in a similar way of curl we have to use the goal deploy-file of the deploy plugin.

mvn deploy:deploy-file --settings=$PWD/settings.xml -Dfile=vim-common-7.4.629-6.el7.x86_64.rpm -DgroupId=molnar.vim -DartifactId=vimrpm -Dversion=1.0 -DrepositoryId=localnexus -Durl=http://localhost:8081/repository/MyRpms/ 
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom ---
Uploading to localnexus: http://localhost:8081/repository/MyRpms/molnar/vim/vimrpm/1.0/vimrpm-1.0.rpm
Uploaded to localnexus: http://localhost:8081/repository/MyRpms/molnar/vim/vimrpm/1.0/vimrpm-1.0.rpm (6.2 MB at 17 MB/s)
Uploading to localnexus: http://localhost:8081/repository/MyRpms/molnar/vim/vimrpm/1.0/vimrpm-1.0.pom
Uploaded to localnexus: http://localhost:8081/repository/MyRpms/molnar/vim/vimrpm/1.0/vimrpm-1.0.pom (416 B at 5.5 kB/s)
Downloading from localnexus: http://localhost:8081/repository/MyRpms/molnar/vim/vimrpm/maven-metadata.xml
Downloaded from localnexus: http://localhost:8081/repository/MyRpms/molnar/vim/vimrpm/maven-metadata.xml (292 B at 7.5 kB/s)
Uploading to localnexus: http://localhost:8081/repository/MyRpms/molnar/vim/vimrpm/maven-metadata.xml
Uploaded to localnexus: http://localhost:8081/repository/MyRpms/molnar/vim/vimrpm/maven-metadata.xml (292 B at 4.8 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.007 s
[INFO] Finished at: 2020-02-24T22:15:08+01:00
[INFO] ------------------------------------------------------------------------

Few remarks about this command:

  • User and password are hidden in the settings.xml file
  • You have to specify additionnal parameters: groupId, artifactID and version. All this things only make sense in a maven context. In a RPM context it doesn't make sense!
  • useless files have been automatically generated
  • Even if you don't have seen any warnings the RPM has been renamed from vim-common-7.4.629-6.el7.x86_64.rpm to vimrpm-1.0.rpm.

maven renamed upload

Under the hood

The automatic renaming is really annoying and it could not be avoid if you are using maven deploy. It happens because maven has been written to handle artifacts following maven naming. If you look at the code in the maven plugin in DeployFileMojo.java, you will see that an URL is build using different factories from Maven classes. So it's important to understand that you cannot specify the URL of the artifact. If you need to deploy non-java artifact don't use maven, even if the doc says that artifacts which are not built using Maven can be added to any remote repository using the deploy:deploy-file mojo. Yes you can, but with no control on the name and final URL.

By @Romain JACQUET in
Tags : #java, #nexus, #deploy,