Search code examples
spring-bootgradlebinaryfiles

How to fix springboot gradle:processResources with binary files


I'm trying to create a SpringBoot application using gradle. But I have some issue with the processResources task.

In my case, I have some JAR files in 'src/main/resources/libs', these files are used to my JAVA BuildPath.

I have allready try to add filter on application.properties only, but it's doesn't work.(Gradle processResources - file contains $ character)

I have this error on 'processResources' task:
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 ^


Solution

  • 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')]
            )
        }
    }
    

    Similar to the following answer: https://stackoverflow.com/a/36731250/2611959