You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
funtestGeneratedResource() {
val resource =object:Any() {}.javaClass.getResourceAsStream("/generated-resource.txt")
if (resource ==null) {
throwRuntimeException("Couldn't load generated resource")
}
}
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.
The text was updated successfully, but these errors were encountered:
big-andy-coates
added a commit
to big-andy-coates/gradle-modules-plugin
that referenced
this issue
Jan 17, 2024
fixes: java9-modularity#227
Enhance `TestTask` to patch-in additional resource directories containing generated resources, as added via `org.gradle.api.tasks.SourceSetOutput.dir()` methods, when running unit tests, so that all resources are accessible.
The
org.gradle.api.tasks.SourceSetOutput
object allows other parts of the system to register additional directories that contain generated resources via thedir
methods.For example, given the following in the build script:
Then a unit test should be able to load the 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()
orSourceSetOutput.getResourcesDir()
that are accessed by theTestTask
class in this plugin. Instead, they can be accessed viaSourceSetOutput.getDirs()
.TestTask
needs to be enhanced to include these additional resource directories.The text was updated successfully, but these errors were encountered: