简体   繁体   中英

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.

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

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.

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'
}
bootWar {
    archiveFileName.set 'service.war'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM