13

I have development related directory src/main/resources/certs/test which is needed for one external library. This has some cert files which are not needed in production build.

At the moment I exclude everything under that directory with following block in build.gradle:

sourceSets {
    main {
        resources {
            exclude '**/test/*'
        }
    }
}

This does it job well, but leaves ugly empty directory test lying there. What are my options to not include this directory in final war?

I've tried excluding '**/test', but it doesn't work at all.

I use war plugin and Gradle 1.2

ilvez
  • 1,235
  • 3
  • 16
  • 27

3 Answers3

35

Using Gradle 1.1, this works for me:

apply plugin: 'war'

sourceSets {
    main {
        resources {
            exclude '**/test/*'
            exclude 'certs/test'
        }
    }
}
Michael Easter
  • 23,733
  • 7
  • 76
  • 107
  • You can use the following to exclude every file and folder and sub-folder: `resources { exclude '*.*' exclude '**/' }` – Mr-IDE Jul 21 '16 at 10:13
9

I had a similar problem with production files in a JAR file (though mine were not test files). I solved it with the following:

jar {
    exclude ("DIRECTORY-TO-EXCLUDE/**")
}

e.g.

jar {
    exclude ("test/**")
}
toddcscar
  • 1,115
  • 9
  • 12
0

A common projet layout is to put test files under the test source set, this way you don't have to exclude them from the main source set.

From the Gradle documentation, the default project layout is like this:

src/main/java       Production Java source
src/main/resources  Production resources
src/test/java       Test Java source
src/test/resources  Test resources
David Levesque
  • 22,181
  • 8
  • 67
  • 82
  • I know the standard layout. Question is not about layout of my project and how standard it is, but Gradle funcionality to exclude directories. I can reformat my project, but initial question remains. – ilvez Sep 27 '12 at 20:23
  • This layout is standard, and also [totally impractical](http://blog.ltgt.net/maven-is-broken-by-design) (search for "project layout"). Having dropped it is something I enjoy every day. – maaartinus Jul 19 '14 at 14:56