Multiple fileTree in resources section

I’m trying to migrate a Maven1 build to Gradle. This is my first real Gradle build, so I’m probably doing something wrong. The issue I face is that there are several directories with their related Ant style matching patterns. Inspired by the users manual (Chapeter 16.3 File Trees: http://www.gradle.org/docs/current/userguide/working_with_files.html#sec:file_trees) the best I can come up with is the build file below. Unfortunately this causes Gradle to fail with the message

Could not find method main() for arguments [build_4fd8glkjbn7dka51fkr3r4chr3$_run_closure1_closure2@4959f789] on root project ‘gradleq’.

By the way this is easily reproducible, no other files needed. My Gradle version is 2.0.

My question is either: What am I doing wrong? Alternatively: How can I get two resource directories with associated matching patterns?

apply plugin: 'java'
  sourceSets {
    main {
        java {
            srcDir 'src/java'
        }
        resources {
          srcDirs [
            fileTree(dir: 'src/etc', includes: [ '*.xml', '*.properties' ]),
            fileTree(dir: 'other/resources', includes: [ '*.xml', '*.properties' ])
          ]
        }
    }
}
1 Like

The correct syntax is:

sourceSets {
    main {
        java {
            srcDirs = ['src/java'] // want to override the default
        }
        resources {
            // cannot omit the '=' because this would try to
             // index into the 'srcDirs' value
            srcDirs = ['src/etc', 'other/resources']
             include '*.xml', '*.properties'
// or: '**/*.xml', '**/*.properties'
        }
    }
}

As can be seen above, include filters are currently per source directory set (e.g. ‘sourceSets.main.resources’), not per source directory.