Question

I have resource file with some tokens that need to be replaced with file paths using the java plugin task 'processResources'. Does gradle provide a way in which, the token value is an expression?

1) src/resources/config.properties file has a token: SRC_ROOT_DIR = @SRC_ROOT_DIR@

2) build.gradle file contains the following:

processResources{
   filter ReplaceTokens, tokens:[SRC_ROOT_DIR: project.projectDir]
}

This throws an exception saying : could not copy file '..src\resources\config.properties' to '..build\resources\main\config.properties'

Was it helpful?

Solution

Running your snippet with --stacktrace gave me:

...

Caused by: org.gradle.api.GradleException: Could not copy file 
'C:\bss\zz\src\main\resources\config.properties' 
to 'C:\bss\zz\build\resources\main\config.properties'.

...

Caused by: java.lang.ClassCastException: 
java.io.File cannot be cast to java.lang.String
...

Changing project.projectDir to project.projectDir.name (or path) solved it:

filter ReplaceTokens, tokens:[SRC_ROOT_DIR: project.projectDir.path]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top