leiblix
leiblix

Reputation: 696

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.

Upvotes: 13

Views: 18058

Answers (5)

Maicon Mauricio
Maicon Mauricio

Reputation: 3001

If one want to change the name of the archive dynamically, use system property with a default in either:

bootWar {
    archiveFileName.set project.getProperty('warName') ?: 'service.war'
}

or

bootWar {
    archiveName project.getProperty('warName') ?: 'service.war'
}

then it's possible to customize the war file name using:

./gradlew -PwarName=<custom_name>.war bootWar

Upvotes: 0

TMRnoMEM
TMRnoMEM

Reputation: 91

bootWar {
    archiveFileName.set 'service.war'
}

Upvotes: 9

akarahman
akarahman

Reputation: 358

codemule - answer is correct, with a different error message when archiveFileName was used in bootWar task. I am using Gradle 6.5.1.

With the below bootWar task

bootWar {
    archiveFileName 'bst.war'
}

I got the error message

A problem occurred evaluating root project 'example'.
> No signature of method: build_1z1dezuc71i4g9wsz51um0q6o.bootWar() is applicable for argument types: (build_1z1dezuc71i4g9wsz51um0q6o$_run_closure1) values: [build_1z1dezuc71i4g9wsz51um0q6o$_run_closure1@7abe6e]

It disappeared when bootWar task was configured with archiveName

bootWar {
    archiveName 'example.war'
}

Upvotes: 2

codemule
codemule

Reputation: 599

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.

Upvotes: 8

M.Ricciuti
M.Ricciuti

Reputation: 12096

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

Upvotes: 20

Related Questions