gradle - Grails 4 - Gradle 'assemble' 任务不生成 .war.original 存档

标签 gradle grails build.gradle grails-4

我刚刚将我的 Grails 网络应用程序从 3.2 版升级到 4.0 版。

我在 build.gradle 中有一个 provided 依赖项(相当常见的配置):

dependencies {
    ...
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    provided "org.springframework.boot:spring-boot-starter-tomcat"
    ...
}

我刚刚注意到,通过执行 Gradle assemble 任务,我不再获得 myApp.war.original 存档(过去是在没有提供所有内容的情况下构建的libs),但只有一个包含提供的依赖项。

我是不是漏掉了什么?我真的很想在 lib-provided 文件夹中保留那些 ~4MB 的 jar。 提前致谢!


更新 1

按照@ck1 的建议,我将provided 依赖项更改为providedCompile,但结果是一样的。 虽然我已经使用了 war 插件,但我注意到 assemble 任务启动的任务序列是:

> Task :assetCompile
Finished Precompiling Assets
> Task :compileJava
> Task :compileGroovy
> Task :buildProperties
> Task :processResources
> Task :classes
> Task :compileWebappGroovyPages NO-SOURCE
> Task :compileGroovyPages
> Task :compileGsonViews
> Task :findMainClass
> Task :bootWar
> Task :war SKIPPED
> Task :assemble

因此 war 任务被跳过以支持新的 bootWar 任务(在 Gradle 3 中不可用,由 Grails 3 使用)。 有什么办法强制吗?还是插件应该已经支持了?


更新 2

经过一些研究,我添加到build.gradle

war {
    enabled = true
}

并且能够让 war 任务执行:

> Task :assetCompile
Finished Precompiling Assets
> Task :compileJava
> Task :compileGroovy
> Task :buildProperties
> Task :processResources
> Task :classes
> Task :compileWebappGroovyPages NO-SOURCE
> Task :compileGroovyPages
> Task :compileGsonViews
> Task :findMainClass
> Task :bootWar
> Task :war           // not skipped
> Task :assemble

我基本上到达了我想去的地方,即获得一个没有所有提供的依赖项的 .war 存档;与以前不同的是,不是一对 .war 文件(myApp.warmyApp.war.original)而是一个名为 myApp.war 不包括不需要的东西。

但我仍然很困惑,因为 Spring Boot's Gradle plugin documentation声明 bootWarwar 的扩展。

The bootRepackage task has been replaced with bootJar and bootWar tasks for building executable jars and wars respectively. Both tasks extend their equivalent standard Gradle jar or war task, giving you access to all of the usual configuration options and behaviour.

然后Spring Boot 2.0 Migration Guide状态 war 任务预计将被跳过:

The bootRepackage task has been replaced with bootJar and bootWar tasks for building executable jars and wars respectively. The jar and war tasks are no longer involved.

那么,我又错过了什么?

最佳答案

您应该替换 providedprovidedCompileprovidedRuntime来自 war 的依赖配置插件。

These two configurations have the same scope as the respective compile and runtime configurations, except that they are not added to the WAR archive.

引用:

https://docs.gradle.org/4.10.2/userguide/war_plugin.html

关于gradle - Grails 4 - Gradle 'assemble' 任务不生成 .war.original 存档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59323898/

相关文章:

maven - Gradle设置中的Gradle存储库而不是构建?

Android studio - 在 gradle 中转换 API 的目的

java - 如何在 gradle bootRun 结束时运行附加任务

grails - 在发布时是否编译了grails插件

android - DexArchiveMergerException : Unable to merge dex

Gradle basedir 属性

grails - 在 Grails 中使用动态查找器搜索值

parsing - XmlSlurper解析查询结果

gradle - 如何在build.gradle中声明gradle版本5.0?

heroku - 如何在不使用 gradle publish 命令的情况下发布 Gradle 工件