gradle custom war task webAppDirName

柔情痞子 提交于 2019-12-07 14:21:28

问题


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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/15392919/gradle-custom-war-task-webappdirname

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!