Gradle war 自定义 - 文件夹名称

Gradle war customization - folder name

我需要在我的 war 文件中包含其他文件夹。 我找到了以下文档页面:https://docs.gradle.org/current/userguide/war_plugin.html 并按照那里的例子(仅相关部分):

    war {
       webInf { from 'src/additionalWebInf' } // adds a file-set to the WEB-INF dir.
    } 

它正确移动了 src/additionalWebInf 文件夹的内容,但是我需要将内容放在 webInf 中的文件夹中,而不是直接放在 webInf 中。 目前情况:

app.war/WEB-INF/file1
app.war/WEB-INF/file2
app.war/WEB-INF/fileN

期望的情况:

app.war/WEB-INF/myCustomFolder/file1
app.war/WEB-INF/myCustomFolder/file2
app.war/WEB-INF/myCustomFolder/fileN

如何使用 gradle 将文件移动到 webInf 中的自定义(新)文件夹?

最简单的做法是向 additionalWebInf 添加另一个级别,这样文件就位于 src/additionalWebInf/myCustomFolder/fileN.

回答您的问题:阅读 documentation the webInf closure configures a CopySpec

所以你可以做到

war {
   webInf { 
      from 'src/additionalWebInf' 
      into 'myCustomFolder'
   }
}

war {
   webInf { 
      with copySpec({
         from 'src/additionalWebInf1' 
         into 'myCustomFolder1'
      })
      with copySpec({
         from 'src/additionalWebInf2' 
         into 'myCustomFolder2'
      })
   }
}