且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何用gradle构建WAR文件?

更新时间:2023-01-15 14:39:57

我想您除了war插件外,还已经将spring boot gradle插件应用于了您的项目?那么这种行为是正常的,因为Spring Boot插件将禁用 jar war 任务,并将其替换为 bootWar bootJar 任务.

I guess that you have applied the spring boot gradle plugin to your project, in addition to the war plugin ? then this behaviour is normal, since the Spring Boot plugin will disable jar and war tasks and replace these with bootWar and bootJar tasks .

同时应用了spring boot和war插件:

With both spring boot and war plugin applied:

./gradlew war
15:35:09: Executing task 'war'...

> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :war SKIPPED

BUILD SUCCESSFUL in 0s
2 actionable tasks: 2 up-to-date
15:35:10: Task execution finished 'war'.

注意 SKIPPED 消息

$ ./gradlew bootWar
15:36:35: Executing task 'bootWar'...

> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :bootWar

BUILD SUCCESSFUL in 1s
3 actionable tasks: 1 executed, 2 up-to-date
15:36:37: Task execution finished 'bootWar'.

然后您将在 build/libs 下获得预期的 war 文件.

Then you will get the expected war file under build/libs.

您仍然可以按照以下说明重新启用标准的jar/war任务:

You can still re-enable the standard jar/war tasks as explained here : https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/#packaging-executable-wars-deployable (if you need to produce normal archives and not executable archives)

关于Tomcat问题:安装Tomcat 8.5.

Regarding the Tomcat issue: install Tomcat 8.5.