Java Gradle:自定义源设置为主和测试的依赖项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21161845/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle: custom source set as dependency for the main and test ones
提问by Anton Moiseev
I've created custom source set in Gradle project to keep all generated code:
我在 Gradle 项目中创建了自定义源集以保留所有生成的代码:
sourceSets {
generated {
java {
srcDir 'src/generated/java'
}
resources {
srcDir 'src/generated/resources'
}
}
}
I want to make the result of this source set's code compilation available at compile and run time for main
and test
source sets.
我想要在编译可用此源集合的代码编译的结果,运行时间main
和test
源集。
What's the right semantic way to do it in Gradle?
在 Gradle 中正确的语义方式是什么?
UPDATE:
更新:
As suggested here: How do I add a new sourceset to Gradle?doesn't work for me, I still get java.lang.ClassNotFoundException
when I launch my app (though compilation and unit tests run fine). Here is what I tried:
正如这里所建议的:How do I add a new sourceset to Gradle? 对我不起作用,java.lang.ClassNotFoundException
当我启动我的应用程序时我仍然得到(尽管编译和单元测试运行良好)。这是我尝试过的:
sourceSets {
main {
compileClasspath += sourceSets.generated.output
runtimeClasspath += sourceSets.generated.output
}
test {
compileClasspath += sourceSets.generated.output
runtimeClasspath += sourceSets.generated.output
}
}
采纳答案by Peter Niederwieser
sourceSets {
main {
compileClasspath += generated.output
runtimeClasspath += generated.output
}
}
Same for the test
source set.
test
源集相同。