Can a custom task load resources from it's jar

I’ve packaged a custom task into a jar with some custom resource files.When I use the task by either adding it to the classpath via a buildscript {…} closure or by adding it to /lib, the task fails to load the resource file. You can see from the method below that I’ve tried nearly all the ways java provides for loading a resource. The ‘url’ variable is always null.

def buildFile(path) {

//def url = RefreshSchema.class.getResource(path)

//def url = getClass().getResource(path)

def url = getClass().getClassLoader().getResource(path)

//def url = ClassLoader.getSystemResource(path)

//def url = ClassLoader.getResource(path)

println(‘url is:’ + url.toString() + ’ for path:’ + path)

return new File(new URI(url.toString()))


I confirmed the resource file is in the jar. I printed the contents of the ClassLoader.getURLs() to make sure my task’s jar is on teh classpath. Not sure where else this could have gone wrong


I would assume this would work as well. Is there anyway you could put a little sample project together that shows this bug that I could use to diagnose the issue?

thank you much for the interest. As is often the case while creating the sample project, I can no longer reproduce the problem. We can safely assume I had a user error typo in the original code somewhere. Most likely in the name of my resources.

No problems. If you do hit it again, just post back here and I’ll open it back up.