gradle custom war task webAppDirName

2019-05-16 10:37发布

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
}

But this is still pulling in the contents of src/main/webapp instead of src/anotherfolder/webapp

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

标签: war gradle
2条回答
Rolldiameter
2楼-- · 2019-05-16 10:51
task myWarTask(type: War) {
    from 'src/anotherfolder/webapp'
    version ""
    destinationDir = file("$buildDir/libs")
    baseName = 'myWarName'
    classpath = configurations.myWarConfiguration
}
查看更多
We Are One
3楼-- · 2019-05-16 11:00

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"
    ...
}

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 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.

查看更多
登录 后发表回答