Creating file while using gradle testkit

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.



task createJson {
	doFirst {
		def jsonFile = new File(outputJsonFile)

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:

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

1 Like

Thanks, that solved it!