GradleUp / shadow

Gradle plugin to create fat/uber JARs, apply file transforms, and relocate packages for applications and libraries. Gradle version of Maven's Shade plugin.
https://www.gradleup.com/shadow/
Apache License 2.0
3.76k stars 395 forks source link

Exclude relocated classes from minimization #610

Open Brikman opened 4 years ago

Brikman commented 4 years ago

In my case, I have a gradle project (module) without any classes at all, but there is an imported dependency with the class I wish to make my main class in the resulting jar (actually this class is ready-to-use main class with psvm inside). I relocate this class from the library into my module's classpath and then build and minimize jar to shrink out all the other library classes except that one that was just relocated. Unfortunately, relocated class does not appear in the resulting jar. Although if I disable minimization, this class will appear on the desired place, as well as tons of other classes from this library I don't need.

Here is my shadowJar snippet:

shadowJar {
    . . .
    def libraryMainClass = 'path.to.ExternalMain'
    def localMainClass = 'path.to.LocalMain'
    relocate libraryMainClass, localMainClass

    manifest {
        attributes 'Main-Class': localMainClass
    }

    minimize()
}

So how could I keep relocated class in the minimized jar?

raccoon1515 commented 4 years ago

I'm interested too.