簡體   English   中英

如何生成一個包含內部依賴關系和外部依賴關系作為外部jar的jar?

[英]How to generate a jar with internal dependencies bundled and external dependencies as external jars?

我有一個Gradle項目,它取決於子項目。 我想創建一個包含所有子項目的“胖罐子”,以及作為外部罐子的外部依賴項。

的build.gradle:

dependencies {
     compile project(':MyDep1')
     compile project(':MyDep2')
     compile 'com.google.guava:guava:18.0'
}

我希望能夠生成以下輸出:

MyProject.jar - >包括MyDep1和MyDep2

libs/guavaXXX.jar - > Guava作為外部lib

我不知道怎么做到這一點。

使用不同的配置來保存內部和外部依賴關系,並將其中一個配置打包到項目工件中。

configurations{
    internalCompile
    externalCompile
}

//add both int and ext to compile
configurations.compile.extendsFrom(internalCompile)
configurations.compile.extendsFrom(externalCompile)

dependencies{
    internalCompile project(':MyDep1')
    internalCompile project(':MyDep2')

    externalCompile 'com.google.guava:guava:18.0'
}

在你的胖jar任務中,只包含來自internalCompile

我終於使用了這個解決方案:

jar {
    subprojects.each {
        from files(it.sourceSets.main.output)
    }
}

distributions {
    main {
        contents {
            exclude subprojects.jar.archivePath.name
        }
    }
}

在我的項目的jar中,我包含了所有子項目輸出的內容。 在分發中,我從子項目中排除了jar(因此它只包含依賴項)。 這可能不是最好的方法,但它很簡單並且有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM