Adding a zip file to Nexus - maven

For some reason I'm struggling wih the following and looking at all the examples on the web are not helping with my use case. I'm at the end of a very complex and odd build cycle with delivers a zip file to my desktop which contains a number of components.
I don't have any control on the creation of the zip file.
I'd like to upload this zip file into Nexus, partly for storage and for release control.
I'm trying to use mvn deploy:deploy-file but when i try to use
zip in my pom file I get the following error :
[ERROR] Unknown packaging: zip # line 6, column 13
A lot of the example suggest using
pom within the pom file, which doesn't error but doesn't upload the zip file.
Command Line I'm using is :
D:\tmp3>mvn deploy:deploy-file -Durl=http://localhost:8081/nexus/content/repositories/snapshots
-DrepositoryId=snapshots
-Dfile=d:\tmp3\test.zip
-DpomFile=pom.xml
Pom file is as simple as I could make it :
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.app</groupId>
<artifactId>testzip</artifactId>
<version>1.0.0.0-SNAPSHOT</version>
<packaging>zip</packaging>
</project>
If I ignore using a pom file and specify the groupID etc as part of the commandline it works.
D:\tmp3>mvn deploy:deploy-file -Durl=http://localhost:8081/nexus/content/repositories/snapshots -DrepositoryId=snapshots -Dfile=d:\tmp3\test.zip
-DgroupId=com.test.app -DartifactId=testzip -Dversion=1.0.0.0-SNAPSHOT
If I remove the packaging tag from the pom, it works, but uploads the zip as a jar !
Eventually I'll need to bubble this up into Jenkins, but for now I'll be happy to get it to work from the command line.
Any ideas ?

Zip files are often deployed as jar into the Nexus. Javadoc and Sources are not really jars as well, but handled as such. Technically, a jar is a zip file anyway.
You can try to deploy it with -Dpackaging=zip over the command line or you just deploy it as jar.

Related

What is the command line approach to download a bunch of jars using maven without POM?

I am using maven and trying to download a bunch of jars.
I donot want to generate the POM file so i am using the below command
mvn dependency:copy -Dartifact=<group>:<artifact-name>:<version> -DoutputDirectory=./localdirectory
How can i use a similar command in maven to download a bunch of artifacts without the POM file?
Any examples using artifactItems would help
The below code snippet does not work
mvn dependency:copy -DartifactItems='com.google.guava:guava:18.0','com.fasterxml.jackson.core:jackson-databind:2.4.3' -DoutputDirectory=./localdirectory

Setting name of jar file while using mvn install:install-file

So previously I was trying to find a way to install jar file which is built in my project to the .m2 folder via run configuration support.
Link for reference.
My main concern then was to not keep any hard coded values in command and to pick most data from pom.xml file. This was achieved successfully, but now I have another problem.
In the project, I have 2 modules module1 and module2.
When module1 is built, it generates 2 files a war file since it is a web based application and second one is jar file which is used to satisfy dependencies of other modules.
The jar file is generated using
<attachClasses>true</attachClasses>
property set in the maven-war-plugin in pom.xml of module1.
So if the module1 artifact id is set as module1-corp, then the jar file is named as module1-corp-classes.jar if the jar is installed using maven-install-plugin. But due to the legacy structure of the project, maven-install-plugin cannot be used and I have to use maven command line via Intellij run configurations to install this file.
So the command I used is
mvn install:install-file -Dfile=${project.build.directory}/${project.build.finalName}.jar -DgroupId=${project.groupId} -DartifactId=${project.artifactId} -Dversion=${project.version} -Dpackaging=jar
This installs the jar file perfectly, only it doesn't append the classes part at the end of jar file. so my jar file is now installed as module1-corp.jar instead of module1-corp-classes.jar which is not working okay with modules which are dependent on it.
I suspect this is due to the way module1 dependency is accessed in module2 which is as follows:
<dependency>
<groupId>module1.groupid</groupId>
<artifactId>module1.artifactId</artifactId>
<version>${module1.version}</version>
**<classifier>classes</classifier>**
</dependency>
This code is in the module2 pom.xml. I believe the classifier part is what is causing the issue, but I cannot change this since it is a legacy project.
So in the end I have two options only
Rename the jar while it is being installed via maven command line
Some other way which can rename the jar via an Intellij run configuration.
I tried using following flag
mvn install:install-file -Djar.finalName=jarname
But this doesn't seem to work as expected.
The install maven plugin allows also to specify the classifier (see: here). So in your example the command would need to be changed to:
mvn install:install-file -Dfile=${project.build.directory}/${project.build.finalName}.jar -DgroupId=${project.groupId} -DartifactId=${project.artifactId} -Dversion=${project.version} -Dpackaging=jar -Dclassifier=classes

Change the artifact name while uploading to Maven Repository through command line

I am new to Maven and looking out for ways to upload many 'XML'(not jars) files to a Maven Repository.
I came across the 'mvn deploy' command which allows me to successfully upload the files to a Maven Nexus Repository.
I am using below command to upload single file successfully. So my XML gets uploaded with name com/xxx/test/test/0.1/test-0.1.xml.
call mvn deploy:deploy-file -DgroupId=com.xxx.test -DartifactId=test -Dversion=0.1 -DgeneratePom=false -DrepositoryId=kepler-releases -Durl=http://example.com:8081/repository/xxx-release -Dfile=xxx/abc.xml
Is there a way that I can upload multiple xml files under this same group 'com.xxx.test' with their existing file names (like abc.xml in this case)?
I saw there is some option -finalName but couldnt find many examples around its use. Any help with this would be appreciated.
Thanks.

cannot deploy zip to Nexus

I'm trying to check a zip file (created by an external process) into Nexus using mvn deploy:deploy-file.
When I run from the command line (Win), everything works and I can see the pom and zip in my snapshot repo. However If I use a maven job in Jenkins to do the same I'm getting the following error :
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Unknown packaging: zip # line 6, column 13
pom looks like :
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.app</groupId>
<artifactId>testApp</artifactId>
<version>1.0.0.0-SNAPSHOT</version>
<packaging>zip</packaging>
</project>
mvn command is :
mvn deploy:deploy-file -DpomFile=d:\testApp.pom -Dfile=d:\testapp.zip
-DrepositoryId=snapshots
-Durl=http://localhost:8081/nexus/content/repositories/snapshots
If I was using the wrong packaging, why does it work for one and not the other ?
This page describes the <packaging> tag: http://maven.apache.org/pom.html#Maven_Coordinates
It says, and I quote:
The current core packaging values are: pom, jar, maven-plugin, ejb, war, ear, rar, par.
Additional plugins can add additional packaging types when they modify the lifecycle.
This information applies to the tag in the pom.
Possible solution: If you comment out or remove the <packaging>zip</packaging> it will stop failing with an error message.
This means when you can use the command with one more -D option
mvn deploy:deploy-file ... -Dfile=somefile.zip -Dpackaging=zip
to publish a file to a maven repository like Nexus or Artifactory. Maven will not complain because its only checking the tag for validity.
However, if you are doing anything else with Maven and that anything requires you to set the packaging type, you will need to find another solution.

Maven: Deploying a jar/war with built in pom.xml file

I don't have a Maven project. What I have is a jar with the pom.xml embedded in the file. When I deploy this via the Artifactory GUI, Artifactory finds the pom and deploys it with the jar. It even recognizes the groupId, artifactId, and version.
When I try using mvn deploy:deploy-file it fails. If I extract the pom, and run mvn deploy:deploy-file with the -DpomFile=pom.xml, it works. Is there a way of deploying this jar with the embedded pom via the Maven command line? Or, do I need to extract the pom.xml first?
I have not heard of the possibility to specify the pom file from archive. I think it is unlikely to be an option, because Maven itself is just a light-weight program, which runs with plugins; and it needs some configurations to run with; and all references to plugins to be used are in those files.
Consider writing an Ant script that will extract the file, run mvn deploy:deploy-file -DpomFile=pom.xml and then delete the file.
The solution looks not very nice, I know, but it should help.
This is an Artifactory feature and not standard Maven behaviour.
Keep in mind that, for example, if you use dependency:unpack-dependencies or the assembly plugin to create some sort of über jar there would be multiple pom.xml files within the jar under the /META-INF/ path so it would be very difficult to select which pom was the true pom.

Resources