Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle 'war' plugin how to change name of an archive

How can I change the name of war?

I already tried (I found these params in documentation https://docs.gradle.org/4.10.2/dsl/org.gradle.api.tasks.bundling.War.html)

war {
baseName = 'service'
archiveName 'service.war'
}

However, this is not working. I am still getting a name with a snapshot version.

./build/libs/search-0.0.1-SNAPSHOT.war

I am using Gradle 4.10 and Spring Boot 2.1.2.RELEASE.

like image 766
leiblix Avatar asked Feb 03 '19 09:02

leiblix


People also ask

How do I set a war name in gradle?

project(':web') { apply plugin: 'war' war { archiveName 'hello-gradle. war' } dependencies { compile project(':core') providedCompile 'javax. servlet:servlet-api:2.5' providedCompile 'org.

How do I change a project name in gradle?

First, open the project directory by right-clicking on the project name and click at show in explorer option. Step 2: Close the android studio, and go to the window explorer of the project directory and rename the root folder with a new name.

What is gradle war plugin?

The War plugin extends the Java plugin to add support for assembling web application WAR files. It disables the default JAR archive generation of the Java plugin and adds a default WAR archive task.


2 Answers

Please refer to this documentation : Spring Boot Gradle reference

To sum up: when applying the Spring Boot gradle plugin together with war plugin, the war task is disabled by default and "replaced" by the SpringBoot bootWar task.

So if you want to configure the war artefact, you will need to configure the bootWar task instead of base war task :

bootWar {
    baseName = 'service'
    archiveName 'service.war'
}

Additional notes:

  • in Gradle 5.x , archiveName has been deprecated, and you should use archiveFileName instead
  • if you set the archiveName property you don't need to set baseName property
like image 73
M.Ricciuti Avatar answered Sep 23 '22 08:09

M.Ricciuti


M. Ricciuti answer is correct, with the caveat that even though archiveName has been deprecated in Gradle 5.x, Spring Boot is still using it in 2.1.6.RELEASE. For example, if the bootWar task was configured with the new archiveFileName property like this:

bootWar {
    archiveFileName 'service.war'
}

you will get this error:

Could not find method archiveFileName() for arguments [service.war] on task ':bootWar' of type org.springframework.boot.gradle.tasks.bundling.BootWar.

Use archiveName for now. See Spring BootWar class Java doc for details. They may add archiveFileName in the future.

like image 24
codemule Avatar answered Sep 23 '22 08:09

codemule