Why does gradle not include XML Schema Definition from resources in the jar

I have a program that reads some configuration from an XML file, and I want to include the schema (.xsd) for that file in the jar so that I can validate the config file matches the schema when I run the program. I think this is because i modified the jar task to build a fat jar from the gradle cookbook. How can I tell gradle to include my resources in the jar?

My source sets are set up in the default location, and my jar task looks like this (to build a standalone executable jar):

jar {
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    manifest {
        attributes 'Main-Class': 'my.package.MainClass'

The resources will be included automatically, if you put them in the right location (‘src/main/resources’ by default). I don’t see why this wouldn’t work in your case, as your configuration of the ‘jar’ task is only adding stuff.

If I change to add runtime dependencies:

from{ configurations.runtime.collect {it.isDirectory() ? it : zipTree(it)}}

The xsd file ends up in the jar, but if I use configurations.compile, it doesnt.

Without more information, my best bet is that something is wrong with your build (scripts). Are you using the ‘java’ plugin? What happens if you remove the ‘from’ line altogether? In any case, for an executable Jar you do want the runtime dependencies.