How do I change the name of the war file being built?

I have a build.gradle file that contains the following:

artifacts { 
    warArchives file: file("${projectDir}/build/libs/${rootProject.name}-${version}.war")
} 

I tried to change the line in the build.gradle file to:

warArchives file: file("${projectDir}/build/libs/myname.war")

but the build process still produces a war file by the name of ${rootProject.name}-${version}.war

I’m not sure how to override. I’m using a build.gradle file that was produced some time ago and I’m using gradle 2.3. I also read and tried passing a command line parameter:

   -Pwar.archiveName=myname.war

But this do not work. How can I override?

You can set the name of the war archive in your build.gradle like so:

war {
    archiveName = 'myname.war'
}
2 Likes

question: How can I override the war archive name on the command line? I can set it in the build.gradle as mentioned above, but I find myself in a situation where for a particular build I have to override the name. I was using

-P war.archiveName=xxx.war

but it does not seem to take. How do i override a name on the build command line?

You would have to define a project property for that. Lets say I do -PwarName=foo.war:

war {
    archiveName = project.property('warName')
}