简体   繁体   English

将某些罐子/组包括到gradle jar中

[英]Include certain jars/group into gradle jar

I have below sample in build.gradle. 我在build.gradle中有以下示例。 My requirement is to include the jars jar1 (with its dependencies) and jar3 (with its dependencies) as part of my final jar. 我的要求是将jars jar1(及其依赖项)和jar3(及其依赖项)作为最终jar的一部分包括在内。 How can I do that ? 我怎样才能做到这一点 ? I have searched a lot for this, although i found a solution here https://stackoverflow.com/a/43374638/1403009 but i can only include one package name as part of jar building task. 我为此进行了很多搜索,尽管我在这里https://stackoverflow.com/a/43374638/1403009找到了一个解决方案,但我只能将一个软件包名称作为jar生成任务的一部分。 In this case, I need multiple such packages/groups to be included as part of my final jar. 在这种情况下,我需要将多个此类包/组作为最终jar的一部分包含在内。

..
..
configurations {
    runTimeJars
}

dependencies {
  configurations.compile.extendsFrom(configurations.runTimeJars)
  runTimeJars'group1:jar1'
  compile 'group1:jar2'
  runTimeJars'group1:jar3'
}

jar {
    zip64 true
    from {
            configurations.runTimeJars.collect { it.isDirectory() ? it : zipTree(it) }
        }
}

Try: 尝试:

jar {
    manifest {
        attributes 'Main-Class': `mainClassName`
    }

    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
        configurations.runTimeJars.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

I didn't test it myself. 我自己没有测试过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM