gradle自定义战争任务webAppDirName [英] gradle custom war task webAppDirName

查看:427
本文介绍了gradle自定义战争任务webAppDirName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的构建文件中有一些gradle war任务,我想更改每个war任务的 webAppDirName 。我试过这个:

I have a few gradle war tasks in my build file, and I would like to change the webAppDirName per war task. I tried this:

task myWarTask(type: War) {
    ext.webAppDirName = 'src/anotherfolder/webapp' // also tried just webAppDirName
    version ""
    destinationDir = file("$buildDir/libs")
    baseName = 'myWarName'
    classpath = configurations.myWarConfiguration
}

但是这仍然在 src / main / webapp 而不是 src / anotherfolder / webapp

我可以配置 webappDirName 在每个war文件的基础上是这样的吗?

Can I configure the webAppDirName on a per war file basis like this?

推荐答案

code> webAppDirName 每个项目的属性,War插件会自动为每个 War 添加一个对应的 code>任务。所以主要的问题是如何从中取消。我认为以下几点应该是可行的:

There is just one webAppDirName property per project, and the War plugin automatically adds a corresponding from to each War task. So the main problem is how to undo that from. I think the following should work:

apply plugin: "war"

webAppDirName = "non/existing/dir"

task myWarTask(type: War) {
    from "src/anotherfolder/webapp"
    ...
}

另一种方法是只使用 War 任务类型,但不是战争插件。然后你必须配置更多的任务属性,并且会失去一些功能,主要与提供的配置和发布战争有关。当然你可以用明确的配置来弥补这一点(如果需要的话)。如果您对细节感兴趣,请查看源代码

An alternative is to only use the War task type, but not the War plugin. You'll have to configure a few more task properties then, and will lose a few features, mostly related to provided configurations and publishing of the War. Of course you can make up for this with explicit configuration (if necessary). If you are interested in the details, have a look at the source code for the War plugin.

PS: webAppDirName 不是一个额外的属性( ext。),而是由 War 插件添加的约定属性。额外的属性仅用于构建脚本中的临时使用。在编写额外的属性时,您可以使用 ext。,但在阅读属性时忽略它。

PS: webAppDirName is not an extra property (ext.), but a convention property added by the War plugin. Extra properties are only meant for ad-hoc use in build scripts. You'd use ext. when writing an extra property, but omit it when reading the property.

这篇关于gradle自定义战争任务webAppDirName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆