How to add xml files from java source directory to output jar


(Curtis Peterson) #1

I have a project that contains beandef.xml files for spring configuration in the src/main/java package. When I compile in gradle none of the files are in the output jar file. Should I be adding the xml files as a dependency like the following:

dependency {

compile fileTree(dir: ‘src’, includes: [’/*.xml,/*.properties’]) }


(Peter Niederwieser) #2

One solution is to move the files into ‘src/main/resources’. Another attempt is to let the sources and resources directories point to the same directory:

sourceSets {
  main {
    resources.srcDirs = ["src/main/java"]
  }
}

If I’m not mistaken, I’ve seen this cause problems with duplicate resources in Jar files though.


(Curtis Peterson) #3

That works! Thanks for your help.