Sushant Sushant - 10 months ago 112
Java Question

Gradle throws an error of expecting EOF, found '<<'.Why?

I am using the below piece of code to copy and filter the properties from the properties file and it is working fine.There are one variable which is not static and I need to pass as a paramter so it could work on correct file.I am using -Penv=test or -Penv=at but I am getting the error.

task createLocalProp(type:Copy) << {
from "templates/"
into ("$buildDir/properties")
def myProps = new Properties()
filter(, tokens: myProps)


C:\GRADLE_WORK\XXXX-GRADLE>gradle -b build_localprop.gradle createLocalProp -Pen

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\GRADLE_WORK\XXX-GRADLE\build_localprop.gradle' line: 37

* What went wrong:
Could not compile build file 'C:\GRADLE_WORK\XXXX-GRADLE\build_localprop.gradle'
> startup failed:
build file 'C:\GRADLE_WORK\XXX-GRADLE\build_localprop.gradle': 37: expecting
EOF, found '<<' @ line 37, column 33.
task createLocalProp(type:Copy) << {

1 error


I'm not sure right now why the compiler error happens, but you should not configure the task in execution phase, but in configuration phase. << syntax is a shortcut for doLast and thus even if it would compile it would probably not work as expected. Remove the << and probably everything is ok.