Open philliplbryant opened 5 years ago
having same problem, have you managed to solved this?
using flyway migration, and sql files still included in the jar.
shadowJar {
exclude '*.sql'
...
}
As this bug does not seem to get fixed I will post a workaround I used. You can use the DontIncludeResourceTransformer for simple exclusions (I have not tested this).
import com.github.jengelman.gradle.plugins.shadow.transformers.DontIncludeResourceTransformer
shadowJar {
transform(DontIncludeResourceTransformer) {
resource = "/path/to/remove.txt"
}
}
If this is not enough you can write a custom transformer which removes the files. Something like this:
import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer
import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext
import shadow.org.apache.tools.zip.ZipOutputStream
// Transformer which removes files we do not want in our final jar
class FileRemoveTransformer implements Transformer {
@Override
boolean canTransformResource(FileTreeElement element) {
String fullPath = element.relativePath.getPathString();
// Add your sophisticated checks here
if (fullPath.equals("/path/to/remove.txt") {
return true;
}
return false;
}
@Override
void transform(TransformerContext context) {
}
@Override
boolean hasTransformedResource() {
return true
}
@Override
void modifyOutputStream(ZipOutputStream os, boolean preserveFileTimestamps) {
}
}
and then
shadowJar {
transform(FileRemoveTransformer)
}
Is there an ETA when this bug is fixed?
This is also happening to me with Gradle 6.3 and the shadow plugin version 6.1.0.
Is this doc incorrect or is this an actual bug?
tried like below : dependencies { exclude "META-INF/.SF" exclude "META-INF/.DSA" exclude "META-INF/*.RSA" exclude "*/.html" exclude "module-info." exclude "Log4j-" exclude "mime.types" exclude "VersionInfo.java" }
hope it helps
shadowJar {
minimize {
exclude("*.dll")
}
shadowJar.archiveFileName = rootProject.name + '.jar'
}
This worked for me
Just commenting to reassure that @Knautiluz minimize
block still works to exclude files properly from the fat jar.
I needed to exclude a bunch of native-image
stuff I didn't need from Micronaut for Cloud Functions and I needed to do it like this.
Actually, after some further testing, a block like the above excluded too many jars
from the bundle. That's not what I expected.
@saxenaraj 's way worked for me I used this to exclude unneeded native libs from JNA and another lib
shadowJar {
dependencies {
exclude "com/sun/jna/sunos*/*"
exclude "**/*-ppc*/*" // Linux/AIX on PowerPC(32/64(le))
exclude "**/*-arm*/*" // 32-bit Linux on ARM
exclude "**/*-x86/*" // 32-bit Win/Linux on x86
}
}
If you don't see a change immediately, do a gradle clean.
Shadow Version:
5.1.0
Gradle Version:
5.3.1
Expected Behavior:
Files should not be included in the shadow jar
Actual Behavior:
Files are included in the shadow jar
Gradle Build Script(s):
task fatJar(type: ShadowJar) { configurations = [project.configurations.runtimeClasspath] manifest.from jar.manifest archiveClassifier = 'all'
}