Simple requirement: Copy resources of the Gradle Plugin into the Builddir. I am currently doing this with the following Copy Action:
class CopyAction implements Action<Copy> {
Project project
private final ClassLoader loader = getClass().getClassLoader()
CopyAction(Project project) {
this.project = project
}
@Override
void execute(Copy copy) {
if (getClass().getProtectionDomain().getCodeSource().getLocation().toExternalForm().endsWith("jar")) {
copy.from(project.zipTree(getClass().getProtectionDomain().getCodeSource().getLocation().toExternalForm()).matching {
include 'somefiles/**'
})
copy.into("${project.buildDir}")
} else {
copy.from(project.fileTree(loader.getResource("somefiles")))
copy.into("${project.buildDir}/somefiles")
}
}
}
The if should be testing if the Plugin is running from the the VCS or from a jar. If the Plugin is not running from a jar, the resources are read locally
It certainly feels like a hack …if their are better ways to Copy Resources of a Plugin to a target Build dir, i would appreciate any pointer. I have haven’t found any documentation concerning this topic
Up to Gradle 6.4 the Copying of Plugin resources with a Copy Action works, with Gradle 6.5.1 not anymore:
With 6.5 the Gradle Testkit seems to be packing the binary’s into a main.jar, which is copied into the Gradle Cache, but without resources. So the the above test fails.
I have open an issue https://github.com/gradle/gradle/issues/15322. Don’t really see that this will be addressed anytime soon.
Also i have a some Example , with reproduces the scenario https://github.com/chhex/gradle-plugin
Any feedback , input great appreciated.