【问题标题】:How to fix springboot gradle:processResources with binary files如何使用二进制文件修复springboot gradle:processResources
【发布时间】:2019-06-02 23:12:10
【问题描述】:

我正在尝试使用 gradle 创建一个 SpringBoot 应用程序。 但我对 processResources 任务有一些疑问。

就我而言,我在 'src/main/resources/libs' 中有一些 JAR 文件,这些文件用于我的 JAVA BuildPath。

我已经尝试仅在 application.properties 上添加过滤器,但它不起作用。(Gradle processResources - file contains $ character)

我在“processResources”任务中遇到此错误:
Could not copy file 'xxx\src\main\resources\libs\myJar1.jar' to 'xxx\build\resources\main\libs\myJar1.jar'. ... Root cause: groovy.lang.GroovyRuntimeException: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed: SimpleTemplateScript11.groovy: 1: unexpected char: '\' @ line 1, column 232. 6wPíÔà¬ÑüçZ Ç�8X›y«Ý«:|8“!\dÖñ%BW$ J ^

【问题讨论】:

  • 第一个问题是:为什么要把一些jar文件放到SOURCE目录下? (源/主/资源)。如果您确实需要在项目中添加一些库,您应该将它们添加到 $projectRootDir/libs 并配置类路径(依赖项)以指向这些。
  • 用于在我的 buildPath 中添加这些文件。而这些 Jar 不在存储库中。
  • 我更新了我之前的评论:你能把这些罐子放在你项目结构的其他地方吗?在src 目录之外。
  • 当我把它放在$projectRootDir/libs 中时,Jar 文件就可以了。但我现在对“*.png”文件也有同样的问题......
  • 我正在使用gradle 5.0,我的 proccessResources 就像我提到的解决方案一样。 processResources { filesMatching('application.properties') { expand(project.properties) } }

标签: spring-boot gradle binaryfiles


【解决方案1】:
processResources {
    filesNotMatching("**/libs/*") {
        expand( // my application properties that should be filtered
                'project': ['version': project.version],
                'build': ['timestamp': new Date().format('dd/MM/yyyy HH:mm')]
        )
    }
}

类似于下面的回答:https://stackoverflow.com/a/36731250/2611959

【讨论】:

    猜你喜欢
    • 2014-11-28
    • 2011-05-27
    • 1970-01-01
    • 2010-11-29
    • 1970-01-01
    • 2019-06-18
    • 1970-01-01
    相关资源
    最近更新 更多