为什么gradle会产生空档案?

时间:2017-06-12 17:34:07

标签: java maven gradle jar build.gradle

我有一个由模块和子模块组成的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. 公共/建造/库/共0.0.1-SNAPSHOT.jar
  3. 公共/ webutils /建造/库/ webutils-0.0.1-SNAPSHOT.jar
  4. 我希望

    • (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)是空的?
    • jar中没有包含(3)中的compiletestCompile依赖项?根据{{​​3}}
      • compile:编译时间依赖性
      • testCompile:编译测试的其他依赖项

1 个答案:

答案 0 :(得分:1)

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