我已经在gradle项目中集成了jacoco,但是对于大多数类,我得到了这样一个错误:“在生成报告的过程中找不到源文件”com/ourprojectname/..…/model/modelone.java“。而且只有在application.java中我没有问题,可以看到代码。我们的架构如下所示:
proj1
-src
--main
---java
----some .java files
... // same proj2 ... projN
src
-main
--java
---com.OurProjectName.api
----Application.java
-test
--test .java files
build.gradle
谁知道我应该如何在gradle中编写代码来修复我的问题(更高描述)?
编辑
allprojects {
group = 'com.OurProjectName.project'
version = '1.1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'jacoco'
// ... other plugins
jacoco {
toolVersion = "0.8.5"
}
// other settings...
}
def otherProjects = ['proj1', ..., ':projN']
test {
useTestNG()
finalizedBy jacocoTestReport
}
otherProjects.each {
evaluationDependsOn it
}
jacocoTestReport {
FileTree sourceTree = files().getAsFileTree()
FileTree classTree = files().getAsFileTree()
otherProjects.each {
sourceTree += project(it).sourceSets.main.allJava
classTree += project(it).sourceSets.main.output.asFileTree
}
getAdditionalSourceDirs().setFrom(sourceTree)
getAdditionalClassDirs().setFrom(classTree)
reports {
xml {
enabled true
xml.destination file("${buildDir}/reports/jacocoXML")
}
html {
enabled true
html.destination file("${buildDir}/reports/jacocoHtml")
}
csv.enabled = false
}
}
dependencies {
implementation project(':proj1')
...
implementation project(':projN')
testImplementation '...'
}
暂无答案!
目前还没有任何答案,快来回答吧!