我有一个包含多个子项目的gradle项目 . 我在库中定义了几个依赖项,其中包含根项目中的版本号和别名 . 现在,只要子项目需要它,它就可以定义具有所需级别的别名,例如:编译 .

root
- build.gradle
    - libraries
        - xercesImpl: 'xerces:xercesImpl:2.8.1',
        - xalan: 'xalan:xalan:2.7.1',
\ project1 : ear
    - build.gradle
        - ear project('project2')
\ project2 : jar
    - build.gradle
        - compile libraries.xercesImpl
        - compile libraries.xalan

由于我已经定义了xercesImpl和xalan作为project1的依赖项,而project1包含在project2 ear中,因此这些jar应该被添加到EAR中,但是它被排除在EAR之外 . 我检查过,传递依赖关系并没有在任何地方声明为false .

我已经使用gradlew打印了依赖树,它只打印了2个以上的 jar ,因为排除了其他包括:

+--- org.hibernate:hibernate:3.1.3
|    +--- commons-logging:commons-logging:1.0.4 -> 1.1
|    |    +--- log4j:log4j:1.2.12
|    |    +--- logkit:logkit:1.0.1
|    |    +--- avalon-framework:avalon-framework:4.1.3
|    |    \--- javax.servlet:servlet-api:2.3
|    +--- ehcache:ehcache:1.1
|    |    \--- commons-logging:commons-logging:1.0.4 -> 1.1 (*)
|    +--- cglib:cglib:2.1_3
|    |    \--- asm:asm:1.5.3
|    +--- asm:asm:1.5.3
|    +--- asm:asm-attrs:1.5.3
|    +--- commons-collections:commons-collections:2.1.1 -> 3.1
|    +--- dom4j:dom4j:1.6.1
|    +--- javax.transaction:jta:1.0.1B
|    \--- antlr:antlr:2.7.6rc1 -> 2.7.6
+--- net.sf.ehcache:ehcache:2.9.0
|    \--- org.slf4j:slf4j-api:1.7.7
+--- xerces:xercesImpl:2.8.1 (*)
+--- xalan:xalan:2.7.1 (*)