Shadow Plugin Gradle: What does mergeServiceFiles() do?

后端 未结 1 1812
小蘑菇
小蘑菇 2021-02-13 01:28

In my build.gradle file I need to add the line:

shadowJar {
    mergeServiceFiles()
}

Otherwise the jar does not run properly. I wonder what th

1条回答
  •  鱼传尺愫
    2021-02-13 02:04

    mergeServiceFiles is declared exactly here and its implementation is as follows:

    /**
     * Syntactic sugar for merging service files in JARs
     * @return
     */
    public ShadowJar mergeServiceFiles() {
        try {
            transform(ServiceFileTransformer.class);
        } catch (IllegalAccessException e) {
        } catch (InstantiationException e) {
        }
        return this;
    }
    

    As you can see it uses ServiceFileTransfomer which is defined here. From its docs:

    Modified from org.apache.maven.plugins.shade.resource.ServiceResourceTransformer.java

    Resources transformer that appends entries in META-INF/services resources into a single resource. For example, if there are several META-INF/services/org.apache.maven.project.ProjectBuilder resources spread across many JARs the individual entries will all be concatenated into a single META-INF/services/org.apache.maven.project.ProjectBuilder resource packaged into the resultant JAR produced by the shading process.

    0 讨论(0)
提交回复
热议问题