【问题标题】:Why does gradle produce empty archives?为什么gradle会产生空档案?
【发布时间】:2017-11-14 06:52:00
【问题描述】:

我有一个由模块和子模块组成的 gradle 项目。

| build.gradle (1)
|- common
    | build.gradle (2)
    |- webutils
        | build.gradle (3)
|- spring
    | build.gradle
    |- security
        | build.gradle

这是build.gradle (1)

dependencies {
    compile project(':common'), project(':common:webutils')
    compile project(':spring'), project(':spring:security')
}

这是build.gradle (2)

dependencies {
    compile project(':common:webutils')
}

这是build.gradle (3)

dependencies {
    compile("javax.servlet:javax.servlet-api:${javaxServletApiVersion}")
    testCompile("javax.servlet:javax.servlet-api:${javaxServletApiVersion}")
    testCompile("org.springframework:spring-test:${springVersion}")
    testCompile("junit:junit:${junitVersion}")
}

当我尝试使用 ./gradlew clean build 构建 jar 时,它会生成以下 jar:

  1. /build/libs/libs-0.0.1-SNAPSHOT.jar
  2. common/build/libs/common-0.0.1-SNAPSHOT.jar
  3. common/webutils/build/libs/webutils-0.0.1-SNAPSHOT.jar

我期待

  • (3) 包含在 (2) 中
  • (2)、(3) 包含在 (1) 中

看(1)

" zip.vim version v27
" Browsing zipfile libs-0.0.1-SNAPSHOT.jar
" Select a file with cursor and press ENTER

META-INF/
META-INF/MANIFEST.MF
~                 

看(2)

" zip.vim version v27
" Browsing zipfile common-0.0.1-SNAPSHOT.jar
" Select a file with cursor and press ENTER

META-INF/
META-INF/MANIFEST.MF

看(3)

" zip.vim version v27
" Browsing zipfile webutils-0.0.1-SNAPSHOT.jar
" Select a file with cursor and press ENTER

META-INF/
META-INF/MANIFEST.MF
com/
com/domain/
com/domain/api/
com/domain/api/common/
com/domain/api/common/webutils/
com/domain/api/common/webutils/URLUtils.class
com/domain/api/common/webutils/RandomUtils.class
~              
  • 为什么我的罐子 (1) 和 (2) 是空的?
  • (3) 中的compiletestCompile 依赖项在哪里没有包含在jar 中?根据documentation
    • compile: 编译时依赖
    • testCompile:编译测试的附加依赖项

【问题讨论】:

    标签: java maven gradle jar build.gradle


    【解决方案1】:

    Java 通常不会将 jar 依赖项捆绑到其他 jar 中。您的MANIFEST.MF 文件的内容是什么?如果要捆绑依赖项,可以查看shadow plugin

    【讨论】:

    • 谢谢@ngreen。我尝试使用此处提供的配置添加影子插件:plugins.gradle.org/plugin/com.github.johnrengelman.shadow,但我仍然没有看到任何添加。另外,我认为使用compile project(':common:webutils')实际上意味着它将“编译时间依赖”。
    • 这是空罐子MANIFEST.MF的内容(只有一行):Manifest-Version: 1.0
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-22
    • 1970-01-01
    • 1970-01-01
    • 2017-06-05
    • 1970-01-01
    • 2015-12-02
    相关资源
    最近更新 更多