Gradle:找不到sourceSets.test.classes [英] Gradle : sourceSets.test.classes not found
问题描述
我试图让我的一个项目(ProjectA)生成一个包含所有测试类的jar文件,以便可以在ProjectB中使用它.
I am trying to get my one of my projects (ProjectA) to generate a jar file containing all the test classes so that it can be used in 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
}
但是,当我将以上内容添加到我的build.gradle
中时,出现以下错误消息:
However, when I add the above to my build.gradle
, I get the following error message:
- 出了什么问题:
评估根项目"gradle_project"时出现问题.
A problem occurred evaluating root project 'gradle_project'.
在任务':testJar'上找不到属性'sourceSets'.
Could not find property 'sourceSets' on task ':testJar'.
我已经在Google和Gradle文档中进行了搜索,以获取更多信息,但是要么删除了它,但没有在我可以找到的任何地方进行记录,或者我使用的是错误的.我怀疑是后者,只是不知道我在做什么错.
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.
我在我的subprojects{}
部分中尝试了相同的代码段,但随后收到以下错误消息:
I have tried the same code snippet inside mysubprojects{}
section but then I got the following error message:
- 出了什么问题:
评估根项目"gradle_project"时出现问题.
A problem occurred evaluating root project 'gradle_project'.
在源集测试上无法获取只写属性'classes'的值.
Cannot get the value of write-only property 'classes' on source set test.
推荐答案
使用以下步骤解决了该问题:
Solved it with the steps below:
步骤1:将代码段移至subprojects{}
部分
Step 1: Move the code snippet inside the subprojects{}
section
步骤2:sourceSets.test.classes
已被删除. sourceSets.test.output
似乎可以解决问题.找到以下内容:创建一罐测试二进制文件-Gradle
Step 2: sourceSets.test.classes
has been removed. sourceSets.test.output
seems to do the trick. Found this: Creating a Jar of test binaries - Gradle
这篇关于Gradle:找不到sourceSets.test.classes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!