Converting Maven resources to gradle resources

(DC) #1

We are moving from Maven to Gradle and I am stuck on the issue below. In our current pom.xml we have this:


We have a unit test that does
I do not want to change the pom.xml as that structure is needed for deployment reasons until we fully migrate to Gradle. I am trying to do the equivalent in gradle with not much success:

    sourceSets {
    main {
        java {
            srcDirs 'src'
        resources {
            srcDirs = [
//            output.resourcesDir = "$buildDir/deploy"

A have a few issues with this:

  1. The files in the config/directory1 and config/directory2 are copied to the root location of the resources folder. I would like to keep the structure the same so there would be a single config directory under the resources dir and then config dir would have directory1 and directory2.
  2. I can set the output.resourcesDir as shown however that means I have to change my java code to
    getClass().getResource("somefile.txt") which is what I have to avoid.


(Sterling Greene) #2

You can configure processResources directly:

processResources {
   from("scripts") {
   from("config/directory1") {
   // etc

(DC) #3

Sterling thank you very much. That has worked perfectly. May I ask if you have any links to more information on this? I searched and read the closest I got was
from 'config/xml-include’
into 'deploy/config/directory1’
from ‘config/directory2’
into deploy/config/directory2’

but that didn’t work.

Thank you very much for your answer.

(Sterling Greene) #4

The Java plugin chapter in the user guide calls out processResources as a Copy task. The Copy task DSL reference has an example.