【问题标题】:How to bundle dependencies in Gradle for multiple applications如何在 Gradle 中为多个应用程序捆绑依赖项
【发布时间】:2015-07-31 01:26:54
【问题描述】:

我想以某种方式启用使用 Gradle 的不同应用程序之间的共享依赖关系管理,并创建了一个“捆绑包”层次结构,基本上打包 Java、Spring、Groovy 和各种测试工件。

“捆绑”的根由如下配置组成:

ext {

    // Spring-specific
    springVersion           = '4.1.7.RELEASE'
    springCore              = "org.springframework:spring-core:${springVersion}"
    springContext           = "org.springframework:spring-context:${springVersion}"
    springBeans             = "org.springframework:spring-beans:${springVersion}"
    springBase              = [springCore, springContext, springBeans]

    ... and more Spring

    // Miscellaneous
    sourceCompatibility = 1.8
    groovy = 'org.codehaus.groovy:groovy-all:2.4.4'
    servlet = 'javax.servlet:javax.servlet-api:3.1.0'
    ... and more
}

subprojects {

    // Enabling Groovy, Wrapper

}

使用如下配置的“Spring bundle”:

dependencies {
    compile(
        groovy,
        springBase,
    )
}

像我的 common-spring 这样的 JAR 工件依赖于上面的“bundle”——而其他项目依赖于 common-spring。

使用 Gradle 的 Maven 插件在本地构建,当我还将“bundles”和“common”安装到我的本地 Maven 存储库时,它可以工作。但是,我不确定这是否是我在 Gradle 中“应该”这样做的方式。

另一种(也许更正确?)方法可能是发布到 Artifactory 并从那里解析工件,因此(希望?)根本不使用任何 Maven-y 东西。

或者是否有一种完全不同且更简单的方法可以集中我使用各种第三方工件的哪些版本?

【问题讨论】:

    标签: gradle


    【解决方案1】:

    是的,这是共享依赖项的好方法,实际上 Gradle 的构建使用了相同的技术。

    一个区别是他们创建了一个地图来存储所有的捆绑包并将它们全部包装在一个列表中。

    ext.libs = [:]
    libs.springCore = ["org.springframework:spring-core:${springVersion}",]
    ...
    

    【讨论】:

    • 但是如果我想在完全不相关的项目之间共享相同的依赖项怎么办? Gradle 似乎没有与 Maven 父 POM 等效的东西。
    猜你喜欢
    • 1970-01-01
    • 2010-09-11
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    • 2018-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多