Strange error copying a file

My setup (remember I am 2 days old with gradle!)

wicket application was maven, I made it into gradle to get some experience.

So I need to copy a large textfile during build. The file is a normal txt file. During the processResources phase I get the following error:

Caused by: 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:
SimpleTemplateScript5.groovy: 1: String too long. The given string is 813517 Uni
code code units long, but only a maximum of 65535 is allowed.

This seems to be because I have in my build file:

// define the profileProperties. This is basically the profile and properties like in maven
def profileProperties = [
 dev:[
  dbdriver:"org.apache.derby.jdbc.EmbeddedDriver",
  dburl:"jdbc:derby:db/eveasset;create=true",
  dbuser:"app",
  dbpassword:"app"
 ],
 test:[prop1:"devValue1", prop2:"devValue2"],
 prod:[prop1:"prodValue1", prop2:"prodValue2"]
]
  // define usedProfile as a global then test if it is set from the command line. If not, then set it to dev
def usedProfile = project.hasProperty("profile") ? project.getProperty("profile"): "dev"
 //if (project.hasProperty("profile")) {
// usedProfile = project.getProperty("profile")
//} else {
// usedProfile = 'dev'
//}
  task showProfile << {
 println usedProfile
}
  // Tell processResources to handle this.
processResources{
 expand(profileProperties[usedProfile])
}

If I comment out the “processResources” part it works perfectly. Is there a way I can tell gradle to exclude the file from being filtered, but it has to be copied?

The ‘expand’ method used Groovy’s ‘SimpleTemplateEngine’, which has its limitations. For larger files, you are better off with the Ant-based ‘filter’ method. For details, see the ‘Copy’ task type in the Gradle Build Language Reference.

I will look into that for now I solved it as follows:

task copyTypeId(type: Copy) {
    from 'tmp/typeid.txt'
    into 'build/resources/main'
}
processResources.dependsOn copyTypeId

This ‘feels’ reasonably clean without having to go into ant(brrrr…). I know this file will never have to be filtered.

In maven you could add several directories and signify filtering false or true. Is this in the pipeline for gradle?

Each copy action of a ‘Copy’ task can have its own filters. See ‘Copy’ in the Gradle Build Language Reference.

If there is interest I wrote an alternative template engine on some bored out Saturday a while back which can handle larger strings:

https://github.com/mbjarland/groovy-streaming-template-engine