Gradle:将自定义源设置为主要和测试依赖项 [英] Gradle: custom source set as dependency for the main and test ones
问题描述
我在Gradle项目中创建了自定义源代码集以保留所有生成的代码:
sourceSets {
generated {
java {
srcDir'src / generated / java'
}
资源{
srcDir'src / generated / resources'
}
}
}
我想让源代码集合的代码编译结果在编译和运行时间为 main
和 test
源集。
在Gradle中使用正确的语义方法是什么?
更新:
如这里所建议的:如何添加一个新的源代码到Gradle?不适用于我,当我启动我的应用程序时(尽管编译和单元测试运行正常),我仍然得到 java.lang.ClassNotFoundException
。这是我试过的:
sourceSets {
main {
compileClasspath + = sourceSets.generated.output
runtimeClasspath + = sourceSets.generated.output
}
test {
compileClasspath + = sourceSets.generated.output
runtimeClasspath + = sourceSets.generated。输出
}
}
sourceSets {
main {
compileClasspath + = generated.output
runtimeClasspath + = generated.output
}
}
与测试
源集相同。
I've created custom source set in Gradle project to keep all generated code:
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.
What's the right semantic way to do it in 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:
sourceSets {
main {
compileClasspath += sourceSets.generated.output
runtimeClasspath += sourceSets.generated.output
}
test {
compileClasspath += sourceSets.generated.output
runtimeClasspath += sourceSets.generated.output
}
}
sourceSets {
main {
compileClasspath += generated.output
runtimeClasspath += generated.output
}
}
Same for the test
source set.
这篇关于Gradle:将自定义源设置为主要和测试依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!