Gradle - War task : how include into the . war file 来自特定路径的特定文件

标签 gradle

我正在处理一个多模块项目。

以下为必填项

apply plugin: 'war'

project(':thymeleaf-02-web') {

    description 'Web (HTML, JS, CSS)'

    dependencies {

        exportedProjects.each{
            if("$it"!=":thymeleaf-02-web")
                compile project("$it")
        }

    }

    webAppDirName = 'src/main/resources'

    war {
        version=''
        baseName = warBaseName
    }

}
webAppDirName 的值与 src/main/resources是完全强制性的,这不是 WEB-INF 的预期工作。位置,因为我正在使用 Thymeleaf , 否则很多 @Test方法失败,关于测试 @Controller关于 Spring .

现在我有了 Web 应用程序所需的强制案例 web.xml文件配置<error-page> .它像往常一样位于 src/main/webapp/WEB-INF/ 内。位置,但是当我创建 .war文件,它被部署到 web.xml从未考虑在内,因此不包括在内。

我尝试了以下添加:
dependencies {

    compile fileTree(dir: "src/main/webapp/WEB-INF/", include: 'web.xml')
    runtime fileTree(dir: "src/main/webapp/WEB-INF/", include: 'web.xml')


    exportedProjects.each{
        if("$it"!=":thymeleaf-02-web")
            compile project("$it")
    }

}

但什么都没有。目前我必须手动复制/粘贴 web.xml将文件放入已部署的 .war文件。

那么正确的配置是什么?

最佳答案

尝试使用 from()调用您的war堵塞:

war {
    from('src/main/webapp/WEB-INF/web.xml') {
        into('WEB-INF')
    }
}

关于Gradle - War task : how include into the . war file 来自特定路径的特定文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50164269/

相关文章:

android - Gradle - 在构建脚本依赖项中添加条件类路径

android - 找不到参数的方法 firebaseAppDistribution()

java - 使用 gradle 外包 java 包以便在其他项目中重用

java - AspectJ + Gradle 配置

android - 如何从 android shrinkResources 中排除资源?

java - 使用 gradle 构建 Java 时跳过部分源代码树

windows - Flutter运行时出错: java. lang.IllegalAccessError

android - 如何在 Gradle Kotlin DSL 中配置 Firebase 性能监控插件扩展

java - Gradle 任务 - 将参数传递给 Java 应用程序

android-studio - 在 Gradle 中,如何指定我的 androidTest 实现应依赖于项目模块的发布版本?