【问题标题】:Disable transitive dependencies for everything expect compile project(...)禁用所有期望 compile project(...) 的传递依赖项
【发布时间】:2015-10-25 21:10:02
【问题描述】:

是否可以将 hibernate 配置为仅从我所依赖的项目中获取传递依赖项 (compile("foobar")) 并禁用其他所有项目的传递性?这就是我到目前为止所尝试的:

configurations.all {
    transitive = false
}
dependencies {
    compile (project(':foobar')) {
        transitive = true
    }
}

这样不行。根本没有传递依赖关系。

建议更新 1

configurations.all {
    dependencies.matching { it.name != 'foobar' }.all {
        transitive = false
    }
}

虽然不考虑来自 foobar 的依赖关系:

compile - Compile classpath for source set 'main'.
+--- project :foobar
+--- junit:junit:3.8.1
+--- org.hibernate:hibernate-c3p0:3.5.6-Final
+--- org.hibernate:hibernate-commons-annotations:3.2.0.Final
+--- org.hibernate:hibernate-ehcache:3.5.6-Final
+--- org.hibernate:hibernate-entitymanager:3.5.6-Final
+--- org.hibernate:hibernate-envers:3.5.6-Final
+--- org.hibernate:hibernate-jmx:3.5.6-Final
+--- postgresql:postgresql:9.1-901.jdbc4
+--- aspectj:aspectjrt:1.5.2
+--- org.apache.tomcat:tomcat-jdbc:7.0.30
\--- org.easymock:easymock:3.2

更新 2

以下解决方案现在对我有用:

dependencies {
    compile project(':foobar')

    compile('org.springframework:spring:2.5.6') { transitive = false }
    compile('org.springframework:spring-mock:2.0.3') { transitive = false }
}

【问题讨论】:

    标签: gradle dependencies transitive-dependency transitivity


    【解决方案1】:

    您必须对其进行过滤以排除特定的依赖项。

    configurations.all {
        dependencies.matching { it.name != 'foobar' }.all {
            transitive = false
        }
    }
    

    【讨论】:

    • 很遗憾没有按预期工作(请参阅原始帖子)。 foob​​ar 仍然没有提供任何依赖项
    • 请注意,如果您的项目路径是:services:web,那么项目名称就是web
    【解决方案2】:

    Gradle 目前不支持全局配置所需的行为。虽然可以通过为每个依赖项显式指定它来实现,因此

    dependencies {
       compile project(':foobar')
    
       compile('org.springframework:spring:2.5.6') { transitive = false }
       compile('org.springframework:spring-mock:2.0.3') { transitive = false }
    }
    

    成功了。不是很好,但工作。

    【讨论】:

      猜你喜欢
      • 2016-06-27
      • 1970-01-01
      • 2013-07-22
      • 2010-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      • 1970-01-01
      相关资源
      最近更新 更多