Resources filtering for war and GRADLE-1566 how to

[digression: I send this question to mailing list 2 days ago but I believe new senders are moderated so I’d like to take this chance to play with forum :)]

With regard to this thread http://gradle.1045684.n5.nabble.com/processResources-filter-corrupts-binary-files-in-certain-environments-td4713752.html and this bug http://issues.gradle.org/browse/GRADLE-1566 :

I wanted to make the workaround proposed working for “war” too, so I tried something like that:

apply plugin: 'jetty'
war {
              from(webAppDirName) {
             exclude '**/*.html'
       }
      from(webAppDirName) {
             include '**/*.html'
             filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [ …]
                                                          ]
            )
       }
}

The configuration works but “from” above only adds, not replaces war’s source dir and I have all files in war duplicated. “Source” property on war is read only.

Finally the following configuration worked for me:

war {
      eachFile {
          if (it.name == 'my.html') {
            it.filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: […])
          }
      }
}

But I’m curious if it’s possible to do this using “froms”?

I also tried something like this:

war {
      exclude '**/*'
      from(webAppDirName) {
             exclude '**/*.html'
       }
      from(webAppDirName) {
             include '**/*.html'
             filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [ …]
                                                          ]
            )
       }
}

because I thought this will exclude everything for default “from” but not from my “froms” since they have their own exclude/include configuration. However, it turns out that now all files are excluded and no files end up in war.

This looks a bit inconsistent for me, because “from” adds sources not overrides, but exclude not only changes existing stuff but also the one I added with their own exclude spec.

Could you offer some thoughts on how the stuff works here?

Hey Lukasz :wink:

  1. You should be able to use eachFile inside of your ‘from’ closure (I think) 2. The current design is that the exclude from the parent copy spec affects the child copy specs regardless if they have their own exclude. E.g. the effective excludes of the child copy spec (created via ‘from’) is merged from the excludes of the parent and children.

Hope that helps!

Hey Szczepan :wink:

thanks for reply

Ad1. I guess in this case that won’t change anything, because if I add any additional from that has the same source that the default one I will get duplicated files

Ad2. ok, I still think it’s a bit of inconsistency, becuase excludes are merged but froms are not

Just doing some cleanup. Can this be considered closed/answered? Or would you like to discuss this further?

I wondered if there’s a way to override the default “from” as new "from"s only add not replaces - so this is still unanswered (but it’s not of any problem for me at this moment)

Hey Łukasz :slight_smile:

There isn’t a way to do it at the moment. I guess there wasn’t a use case for it yet. If you have a use case (“real” one, from your code), feel free to submit a jira ticket.

Cheers!