I want to apply an after test listener per http://www.gradle.org/docs/current/groovydoc/org/gradle/api/tasks/testing/Test.html#afterTest(groovy.lang.Closure)
However, I need to reference a class (src/main/java) that is part of the project inside that closure. Is that possible?
I have tried all forms of playing with test.bootstrapClasspath that I can think of. But nothing seems to work.
I have tried:
test {
bootstrapClasspath += project(':hibernate-core').sourceSets.main.output
...
}
which gives : A problem occurred evaluating root project ‘hibernate-orm’. > Could not find property ‘sourceSets’ on project ‘:hibernate-core’.
The test listener gets executed in the Gradle JVM, not the test JVM(s). So you’d have to put the class on the build script class path, or load it with a class loader.
So then no, there is not a realistic way to do this…
Lets look at this another way… Given a Gradle build, is there anyway I can have some code that is part of the built project called after each test run?
The only way would be to use a ‘URLClassLoader’ and add the classes dir of the code you want to use (and any dependencies), then load the class through this.
We are working towards a more flexible model for being able to designate projects as buildscript dependencies, but this is a long road.