On 20/11/2010, at 1:49 AM, chris wrote:
>
> I realise there's an outstanding bug for this
> (http://jira.codehaus.org/browse/GRADLE-1050) but was wondering to what
> degree we will be able to alter the behavior when duplicate files are in the
> from clauses.
>
> I have a jar task that creates a properties jar to be included in a server
> .ear. I want default property files to be included, but if I put files with
> the same name in a special override directory, I want these copied instead.
> E.g. :
>
> task jarServerConf(type: Jar, dependsOn: processResources) {
> baseName = "myjar"
> classifier = 'server-conf'
>
> from ('src/conf/server')
> {
> // will pick up:
> // ehcache-config.xml
> // jndi.properties
> }
>
> from ('override/conf/server')
> {
> // should pick up and override above IF present:
> // ehcache-config.xml
> // jndi.properties
> }
> }
>
>
> So will this behavior be possible with the solution to GRADLE-1050?
It should. Could you perhaps add a comment to that issue explaining your issue
(just a link to this email thread would be enough), so that we don't forget
about it?
> I'm not
> entirely sure what to do at this point, since I have quite a few of these
> property files (my example shows 2 files for brevity), and I'm not keen on
> having to create some relatively complicated logic to get the overriding
> behaviour (i.e. for each file in override, add an exclude for that file in
> the default from clause) - any suggestions for a workaround are most
> welcome :)
You could do something like this:
task jarServerConf(...) {
...
from('src/conf/server') {
// exclude the file if there is an override for it
eachFile { fcd ->
if (file("override/conf/server/$fcd.path").isFile()) {
fcd.exclude()
}
}
}
from('override/conf/server') {
...
}
}
Another approach:
def overrides = fileTree {
from 'override/conf/server'
}
def serverConfig = fileTree {
from 'src/conf/server'
exclude { fte -> overrides.contains(file("$overrides.dir/$fte.path")) }
}
task jarServerConf(...) {
from serverConfig
from overrides
}
--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz