java – Shadow Plugin Gradle:mergeServiceFiles()做什么?

前端之家收集整理的这篇文章主要介绍了java – Shadow Plugin Gradle:mergeServiceFiles()做什么?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的build.gradle文件中,我需要添加以下行:
shadowJar {
    mergeServiceFiles()
}

否则罐子不能正常运行.我想知道这条线到底是做什么的?
我在Eclipse Luna中使用Gradle插件.我在一个Java项目上创建了jar,它依赖于另一个Java项目.

解决方法

你为什么不自己在代码中调查呢? mergeServiceFiles正好声明为 here,其实现如下:
/**
 * Syntactic sugar for merging service files in JARs
 * @return
 */
public ShadowJar mergeServiceFiles() {
    try {
        transform(ServiceFileTransformer.class);
    } catch (IllegalAccessException e) {
    } catch (InstantiationException e) {
    }
    return this;
}

正如您所看到的,它使用了定义为here的ServiceFileTransfomer.来自其文档:

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.

原文链接:https://www.f2er.com/java/128384.html

猜你在找的Java相关文章