How To Exclude File from a Jar file. Gradle task Jar has a property excludes which takes an array as an input and exclude these files from the Jar file it creates. Let's assume the following directory structure Following example excludes files from the Jar file. task createExcludingFiles(type :Jar){ from ('src'){ excludes = ["main/java/com/ekiras/demo/D.java","main/java/com/ekiras/demo/E.java"] } } This will exclude files D.java , E.java from the jar file. Run the gradle task using command gradle -q createExcludingFiles . The Jar file created will have the following files. META-INF/ META-INF/MANIFEST.MF main/ main/java/ main/java/com/ main/java/com/ekiras/ main/java/com/ekiras/demo/ main/java/com/ekiras/demo/A.java main/java/com/ekiras/demo/C.java main/java/com/ekiras/demo/F.java main/java/com/ekiras/demo/B.java main/java/com/ekiras/demo/p1/ main/java/com/ekiras/demo/p1/X.java main/java/com/ekiras/demo/p1/Z.java main/java/com/ekiras/de...