我试图让我的一个项目(ProjectA)生成一个包含所有测试类的jar文件,以便可以在ProjectB中使用它。
I did a bit of research and found this as possible solution: Create test jar artifact in gradle. That says that the following code snippet should do the trick.
apply plugin: 'java'
task testJar(type: Jar) {
classifier = 'tests'
from sourceSets.test.classes
}
Run Code Online (Sandbox Code Playgroud)
However, when I add the above to my build.gradle, I get the following error message:
- What went wrong:
A problem occurred evaluating root project 'gradle_project'.
Could not find property 'sourceSets' on task ':testJar'.
I have searched on both Google and the Gradle documentation for more information but either it has been removed without documenting it anywhere that I could find or I am using it wrong. I am suspecting the latter, just don't know what I am doing wrong.
I have tried the same code snippet inside mysubprojects{} section but then I got the following error message:
- What went wrong:
A problem occurred evaluating root project 'gradle_project'.
无法在源集测试中获取只写属性“类”的值。
通过以下步骤解决了它:
第 1 步:将代码片段移到该subprojects{}部分内
第 2 步:sourceSets.test.classes已删除。sourceSets.test.output似乎可以解决问题。发现这个:Creating a Jar of test binaries - Gradle
| 归档时间: |
|
| 查看次数: |
4590 次 |
| 最近记录: |