[GRADLE-2313] Build fails if useJUnit() is used explicitly, and `clean` runs before the relevant test task. Created: 17/May/12  Updated: 04/Jan/13  Resolved: 17/May/12

Status: Resolved
Project: Gradle
Affects Version/s: 1.0-rc-3
Fix Version/s: 1.1-rc-1

Type: Bug
Reporter: Gradle Forums Assignee: Luke Daley
Resolution: Fixed Votes: 0


 Description   

The issue is that useJUnit() creates a temp dir (during configuration), that is used during execution.

If `clean` runs before test, this dir will be wiped out. The solution will be to use AbstractTask#getTemporaryDirFactory() instead of using getTemporaryDir().



 Comments   
Comment by Gradle Forums [ 17/May/12 ]

Let me add onto this, so that it can be filed as a real bug. (Please create a JIRA for it.)

useJUnit() is run during the configure phase, calling the JUnitTestFramework constructor. This passes testTask.getTemporaryDir() to ClassFileExtractionManager, which is why ClassFileExtractionManager is in the stack. The crux of the problem is that I'm running the clean task in the execution phase, which deletes the testTask.getTemporaryDir(). So that when it's later used by ClassFileExtractionManager, it's no longer there. TestNGTestFramework does the exact same thing, so I'd guess that this would break too.

This means if you run clean before test and use useJUnit(), the build will not work. Calling clean before running tests seems like a pretty common pattern.

The fix is to call dir.mkdirs(); somewhere. It could easily be pushed down to ClassFileExtractionManager.tempFile() which is plenty logical and is an easy fix. The alternative is create some "ProvidesTempDir" interface with a single method call .getTemporaryDir() which will call .mkdirs() when ever it's called. This would mean that testTask would be passed to ClassFileExtractionManager instead of testTask.getTemporaryDir(). This would offer a more general solution to directories disappearing during the lifecycle.

Create a bug and I might be able to fix it myself.

Comment by Luke Daley [ 17/May/12 ]

Pull request: https://github.com/gradle/gradle/pull/81

Generated at Wed Jun 30 12:18:33 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.