Java – Use Gradle to exclude files from jars

Use Gradle to exclude files from jars… here is a solution to the problem.

Use Gradle to exclude files from jars

I

built a springboot jar and I want to use Gradle to exclude all logback .xml from the fatjar. I tried the following.

jar{
    exclude '/BOOT-INF/lib/**/logback.xml'
}

Can someone help me how to exclude all logback .xml from dependencies using gradle.

Solution

If you don’t care about copying the XML file from src/main/resources to the build/resources/main folder (not just in build/resources/main being copied to War), you can use it like this:

processResources {
    exclude('manual/*.xml')
}

Find more information here

Related Problems and Solutions