2015-04-17 82 views
2

使用gradle玩了一下后,我偶然发现了以下行为,我不确定这是否如预期的那样,或者我做错了什么。Gradle覆盖一般传递=特定依赖关系的错误

默认情况下,我通过告诉编译配置transitive false解释所有传递依赖关系。但是对于一个特定的依赖关系,我只想包含传递依赖关系,所以我将transitive true添加到依赖关系声明中。

但碰巧,gradle忽略了我的覆盖。

这是否符合预期?难道我做错了什么?

以下是一个例子:

的build.gradle

apply plugin: 'java' 

repositories { 
    jcenter() 
} 

configurations { 
    compile { 
      transitive false 
    } 
    testCompile { 
      transitive false 
    } 
} 

dependencies { 
    testCompile('junit:junit:4.12') { transitive true } 
} 

输出

包括每个默认

:dependencies 

------------------------------------------------------------ 
Root project 
------------------------------------------------------------ 

testCompile - Compile classpath for source set 'test'. 
\--- junit:junit:4.12 
    \--- org.hamcrest:hamcrest-core:1.3 

BUILD SUCCESSFUL 

Total time: 3.404 secs 

不含每默认传递依赖但它包括为特定的传递依赖依赖关系

:dependencies 

------------------------------------------------------------ 
Root project 
------------------------------------------------------------ 

testCompile - Compile classpath for source set 'test'. 
\--- junit:junit:4.12 

BUILD SUCCESSFUL 

Total time: 3.352 secs 

回答

1

我不知道您是否可以这样做,因为您已经声明了该配置以排除传递性依赖关系。我看到的另一种模式是其他方式,包括传递和排除依赖声明。

configurations { 
    compile { 
      transitive false 
    } 
    testCompile { 
      transitive false 
    } 
} 

dependencies { 
    testCompile('junit:junit:4.12') { exclude module: 'exclude.this' } 
} 

或更改配置,以排除一切,但一个你想

+0

是,周围的其他方法工作,这就是为什么我认为这_should_工作,我的方式太。只是为了一致。 – uhausbrand

+0

感谢好的“类似主题” - 在gradle用户论坛上的功能,我发现它确实是来自常春藤的剩饭,现在就这样工作。请参阅[链接](https://discuss.gradle.org/t/problem-with-fine-tuning-transitive-dependency-management/1634)。标记为已回答。 – uhausbrand