GradleRunner: missing resources files in .gradle-test-kit/.../main.jar

Hallo All,
the files under src/main/ressouces from my plugin are not included in the main.jar, which is created by the GradleRunner. So some plugin tests fail because the task under test tries to get some files from the main.jar using the zipTree function.
How can I include them into the .jar?

Gradle Version is 7.5.1

Greetings, Tom

If you did not mistype, then your directory is misnamed.

sorry for the typo. I ment src/main/resources. It’s available in the GradleRunner.pluginClasspath() but I need it in the jar in order to run the test successfully

Ah, now I understand what you mean.
I’d like to suggest to instead just get the file as resource instead of unzipping a jar file.
This would be cleaner and also fix the issue you have.

If you insist on extracting the jar, you probably need to either use withPluginClasspath with arguments, giving the actual classpath to inject, or configure the pluginClasspath property on the pluginUnderTestMetadata task accordingly, or not use withPluginClasspath at all but instead publish to some local repository (not maven local) and consume the plugin in the tests from there.

Thank you, Björn,
your solution to configure the pluginClasspath on the pluginUnderTestMetadata task works fine for us!

tasks.pluginUnderTestMetadata {
   pluginClasspath.setFrom(tasks.jar, configurations.runtimeClasspath.get().incoming.artifactView {
       componentFilter {
           it !is OpaqueComponentIdentifier //filter out gradle api
       }
   }.files)
}
1 Like