简体   繁体   中英

How to override files when creating a jar in gradle

We have a java project where we have some default configurations under src/main/resources and there are overwrites under project_root/configDeploy

For our mapred jars we want to copy both configs but allow config/deploy files to overwrite defaults in resources. So we can have myconf.xml in resource and myconf.xml in deploy, but the mapred fat jar generated only has myconf.xml

I have tried two different methods, try to have deploy copy and overwrite the resources conf:

from 'src/main/resources'
from 'conf/deploy'

but this will add two files inside the jar, so it didn't work

Then I tried to add only files from src/main/resources that are not in conf/deploy, something like:

into('conf'){
    from{
        'src/main/resources'
    }
    exclude{file('deploy/conf/')}
}
into('conf'){
   from{
       'deploy/conf'
   }
}

but this didn't work, as a result none of the confs from resources were copies. So question is if I have a two folders with files which some of them have same name how can I include their files in jar so I get files from both folders but for files that are in both I get only the version in second folder.

Thanks for your help!

To avoid the duplicate files in the JAR you can set the duplicates strategy to EXCLUDE on the task.

duplicatesStrategy = DuplicatesStrategy.EXCLUDE

This will cause subsequent attempts to add the file to be ignored. Therefore, if you want files in 'deploy/conf' to take precedence you should define that copy spec first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM