摇篮非标准命名的源集 - 我该如何使它们可用于测试类? [英] Gradle with non-standard named source sets - how do I make them available to the test classes?
问题描述
我有我重新配置,以建立与一个摇篮(传统)的Java项目。构建应,最终输出了许多 JAR
的档案,所以我除以源分成对应于输出细分为档案源集。
I have a (legacy) Java project which I'm re-configuring to build with Gradle. The build should, eventually, output a number of jar
archives, so I've divided to split up the source into source sets that correspond to the subdivision of the output into archives.
文件树看起来是这样的:
The file tree looks something like this:
- project root
- src
- setOne
- java
- ...
- resources
- ...
- setTwo
- java
- ...
- setThree
- java
- ...
- resources
- ...
- test
- java
- ...
- build.gradle
和的build.gradle
我有以下内容:
apply plugin: 'java'
sourceSets {
setOne
setTwo {
compileClasspath += setOne.output
}
setThree
test
}
dependencies {
setOne group: 'foo', name: 'bar', version: '1.0'
}
// Setup dependencies so that compileJava compiles all source sets
// while avoiding cyclic dependencies for main and test
sourceSets.matching { ss ->
!(ss.getName().contains('test') || ss.getName().contains('main'))
}.each { ss ->
compileJava.dependsOn ss.getCompileJavaTaskName()
}
当我尝试建立这个,我得到了一堆从一些类 compileSetTwoJava
目标的警告没有得到解决 - 从 foobar的
库导入到 setOne
。我想这是因为摇篮只给出了 setTwo
访问内置的 setOne
类 - 但为什么是不是能为解决依赖关系的过程中,从 setOne
进口类?
When I try to build this, I get a bunch of warnings from the compileSetTwoJava
target about some classes not being resolved - referring to classes from the foobar
library imported to setOne
. I assume this is because Gradle only gives setTwo
access to the classes built in setOne
- but why isn't it able to resolve the dependencies for the classes imported from setOne
in the process?
我如何设置这个正确?
推荐答案
原来,这只是容易,因为我认为这应该是 - 如果你刚开始出来的正确途径。 Definining
It turns out this was just as easy as I thought it ought to be - if you just start out the right way. Definining
setTwo {
classPath += setOne.runtimeClasspath // instead of setOne.output
}
解决该问题。
更新:
这似乎更好做的依赖关系中,其中一个可以做
It seems even better to do it among the dependencies, where one can do
dependencies {
setTwo sourceSets.setOne.output
}
和得到它的工作。
这篇关于摇篮非标准命名的源集 - 我该如何使它们可用于测试类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!