Creating file while using gradle testkit


(Christian Bremer) #1

When creating a file while using gradle testkit the file ends up in the projectDir for the test instance instead of in the temporary gradle test dir.

gradle.properties

outputJsonFile=build/output.json

build.gradle

task createJson {
	doFirst {
		def jsonFile = new File(outputJsonFile)
		jsonFile.write("DUMMY")
	}	
}

This task creates an file in the projectDir/build/output.json instead of in an tempDir/build/output.json

What am I doing wrong?

I created an minimal sample project: https://github.com/ki82/propertyproblem


(Lance Java) #2

Don’t use new File(...) use file(...) instead which is shorthand for project.file(...)


(Christian Bremer) #3

Thanks, that solved it!