-
Notifications
You must be signed in to change notification settings - Fork 37
Description
The org.gradle.api.tasks.SourceSetOutput object allows other parts of the system to register additional directories that contain generated resources via the dir methods.
For example, given the following in the build script:
val generatedResourcesDir = "generated/resources/test";
sourceSets {
test {
// Add additional output directory for generated resources.
// See org.gradle.api.tasks.SourceSetOutput for more info.
output.dir(layout.buildDirectory.dir(generatedResourcesDir))
}
}
val generateResources = tasks.register("generateResources") {
doLast {
val outputFile = layout.buildDirectory.file("$generatedResourcesDir/generated-resource.txt")
outputFile.get().asFile.parentFile.mkdirs()
outputFile.get().asFile.writeText("some content")
println("Resource file generated at: ${outputFile.get().asFile.absolutePath}")
}
}
tasks.test {
dependsOn(generateResources)
}Then a unit test should be able to load the resource:
@Test
fun testGeneratedResource() {
val resource = object: Any() {}.javaClass.getResourceAsStream("/generated-resource.txt")
if (resource == null) {
throw RuntimeException("Couldn't load generated resource")
}
}See java docs for more info.
At the moment, this gradle-modules-plugin does not patch these additional resource directories into the module-under-test when running unit tests, causing unit tests to fail when attempting to load resources.
These additional resource directories are not included in the SourceSetOutput.getClassesDirs() or SourceSetOutput.getResourcesDir() that are accessed by the TestTask class in this plugin. Instead, they can be accessed via SourceSetOutput.getDirs(). TestTask needs to be enhanced to include these additional resource directories.