# Filtering \*only\* test resources

**URL:** <https://discuss.gradle.org/t/filtering-only-test-resources/6083>\
**Category:** Old Forum Archive\
**Created:** [January 4, 2013, 3:51pm UTC](https://discuss.gradle.org/t/filtering-only-test-resources/6083 "2013-01-04T15:51:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Harrigan](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/david_harrigan/32/119_2.png) [@David\_Harrigan](https://discuss.gradle.org/u/David_Harrigan)\
**Post date:** [January 4, 2013, 3:51pm UTC](https://discuss.gradle.org/t/filtering-only-test-resources/6083/1 "2013-01-04T15:51:00Z")

</div>

Hi,

I’m trying to filter only test resources in each subproject. I have followed this example:

[http://mrhaki.blogspot.co.uk/2010/11/gradle-goodness-add-filtering-to.html](http://mrhaki.blogspot.co.uk/2010/11/gradle-goodness-add-filtering-to.html)

replacing the “all” with \* as necessary in the latest gradle versions and slighly adapted to this:

```gradle
afterEvaluate {
    def processResourcesTasks = sourceSets*.processResourcesTaskName.collect { tasks[it] }
      processResourcesTasks.each {
        it.configure({
            filter(ReplaceTokens, tokens: testProperties)
        })
      }
 }

```

However, this filters _all_ resources in java and also in test. How would I go about restricting this to only filter resources in my src/main/resources folder?

Thank you! 🙂

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [January 4, 2013, 4:18pm UTC](https://discuss.gradle.org/t/filtering-only-test-resources/6083/2 "2013-01-04T16:18:00Z")

</div>

Since you are talking about test resources, I assume you want to filter ‘src/test/resources’. That’s as simple as:

```gradle
processTestResources {
  filter(ReplaceTokens, tokens: testProperties)
  }

```

---

<div class="post-metadata">

**Author:** ![David\_Harrigan](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/david_harrigan/32/119_2.png) [@David\_Harrigan](https://discuss.gradle.org/u/David_Harrigan)\
**Post date:** [January 4, 2013, 4:20pm UTC](https://discuss.gradle.org/t/filtering-only-test-resources/6083/3 "2013-01-04T16:20:00Z")

</div>

Excellent, thank you.

Just one last thing I suppose, if I define the processTestResources, does it replace (or append) other processTestResource(s) in subprojects?

Ta.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [January 4, 2013, 4:25pm UTC](https://discuss.gradle.org/t/filtering-only-test-resources/6083/4 "2013-01-04T16:25:00Z")

</div>

To apply this configuration to all subprojects, wrap it with ‘subprojects { … }’. Or ‘allprojects’, if the current project is to be included as well.

---

<div class="post-metadata">

**Author:** ![David\_Harrigan](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/david_harrigan/32/119_2.png) [@David\_Harrigan](https://discuss.gradle.org/u/David_Harrigan)\
**Post date:** [January 4, 2013, 4:26pm UTC](https://discuss.gradle.org/t/filtering-only-test-resources/6083/5 "2013-01-04T16:26:00Z")

</div>

ta. 🙂
