在我的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.