How to deploy Jar using uploadArchives for war project


(Sandeep Rao) #1


Running uploadarchives deploys the war file to the nexus rather than jar file. I need the jar file as other projects depend on this project. I tried to use artifcats but it thorws an error

artifacts {
archives jar

A POM can not have multiple main artifacts. Already have MavenArtifact project:war:war:null, trying to add MavenArtifact project:jar:jar:null

Can any one help me how i can do this ?

(Karl-Johan Karlberg) #2

I would assume your full buildfile contains the ‘war’ plugin

This says the the ONE built artifact is a war file and not a jar :wink:

According to maven each project can have one and ONLY one artifact (hence your error).

The question is then: what are you trying to accomplish? Do you want BOTH the jar and war on your nexus? Or just the jar? Why would you need a jar built from the same source as a war?

I my mind a war is an “application” a a jar is a “library”. A “library” is typically something you refer to from other libraries or applications and an application is never refered by anything. They are shipped somewhere. If I venture a guess it would seem that you have common code in your war that you want to publish on nexus. I would reccomend that this code is pulled out of the war project and into a separate project. This could be an excellent usecase of a multi-module build.

I would like some more details on your build to better answer the question.

(Sandeep Rao) #3

Thanks for replying!

Your guess is right, I have some common code that needs to be used by other projects and also this project is deployed as application.

Is it possible to create a jar and upload it to nexus through uploadarchives task and generate war when running assemble task in same project ?

(Karl-Johan Karlberg) #4

I will argue that you will be in a better place if you create a multi module like:


And declare MyWar depending project MyShardLib

Then each project deploys one thing to nexus.

in project MyWar you apply plugin “war” and MySharedLib applies plugin “java”

In the root project no plugins are added, but here you create your wrapper…

The the lovely userguide for more details on multi modules.

(Chrigi) #5

I have the same problem, different usecase though. I also wonder if it’s possible to deploy the jar, when the war plugin is used or in the best case, both. The jar is needed to compile extensions which can be loaded into the running webapp.

A multi project build is possible but it adds complexity and I try to avoid that if there is not a really good reason.

(Prasad U) #6

I also have the same requirement - upload jar & war from a project that has War plugin.
was there a final answer to this?

(Robert Paige) #7

I also have this problem.

My project generates a ~300k jar that I want to upload to artifactory as a release artifact. But I also generate a 21MB war that contains mostly dependencies; I see no reason to clutter Artifactory with 99% duplicate files.

Has anyone figured out how to upload a jar from a war project without rewriting my project into multiple submodules, which will play havoc with my project?