我正在尝试将Gradle TestKit与JaCoCo集成。我正在使用这个插件 https://github.com/koral--/jacoco-gradle-testkit-plugin
(在包括我的插件的测试项目中)创建gradle属性,例如:
org.gradle.jvmargs:-javaagent:{someDirsHere}/.gradle/caches/modules-2/files-2.1/org.jacoco/org.jacoco.agent/0.8.1/9aa64427abccf89cfc44a72acaf9d288d80deb8b/org.jacoco.agent-0.8.1-runtime.jar=destfile={someDirsHere}/build/jacoco/test-integration.exec
主项目中的JaCoCO设置如下:
jacocoTestReport {
sourceSets sourceSets.main
executionData = rootProject.files("${buildDir}/jacoco/test.exec", "${buildDir}/jacoco/test-integration.exec")
}
但是,似乎某些东西仍然锁在test-integration.exec文件中。 (如果我将其删除,一切正常,可以)
异常为( java.io.IOException:该进程无法访问文件,因为另一个进程已锁定文件的一部分):
org.gradle.api.UncheckedIOException: Failed to capture fingerprint of input files for task ':quality-plugin:jacocoTestReport' property 'executionData' during up-to-date check.
at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository.fingerprintTaskFiles(CacheBackedTaskHistoryRepository.java:360)
at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository.createExecution(CacheBackedTaskHistoryRepository.java:163)
at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository.access$100(CacheBackedTaskHistoryRepository.java:76)
at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository$1.getCurrentExecution(CacheBackedTaskHistoryRepository.java:123)
at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.ensureSnapshotBeforeTask(DefaultTaskArtifactStateRepository.java:162)
at org.gradle.api.internal.changedetection.changes.ShortCircuitTaskArtifactStateRepository$RerunTaskArtifactState.isUpToDate(ShortCircuitTaskArtifactStateRepository.java:89)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:50)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
at org.gradle.execution.taskgraph.LocalTaskInfoExecutor.execute(LocalTaskInfoExecutor.java:42)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:277)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:262)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:135)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecutor.java:200)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.executeWithWork(DefaultTaskPlanExecutor.java:191)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.api.UncheckedIOException: Failed to create MD5 hash for file content.
at org.gradle.internal.hash.DefaultStreamHasher.hash(DefaultStreamHasher.java:40)
at org.gradle.internal.hash.DefaultFileHasher.hash(DefaultFileHasher.java:40)
at org.gradle.api.internal.changedetection.state.CachingFileHasher.snapshot(CachingFileHasher.java:89)
at org.gradle.api.internal.changedetection.state.CachingFileHasher.hash(CachingFileHasher.java:67)
at org.gradle.api.internal.changedetection.state.SplitFileHasher.hash(SplitFileHasher.java:64)
at org.gradle.api.internal.changedetection.state.DefaultFileSystemSnapshotter.snapshot(DefaultFileSystemSnapshotter.java:179)
at org.gradle.api.internal.changedetection.state.DefaultFileSystemSnapshotter.snapshotAndCache(DefaultFileSystemSnapshotter.java:165)
at org.gradle.api.internal.changedetection.state.DefaultFileSystemSnapshotter.snapshotAndCache(DefaultFileSystemSnapshotter.java:149)
at org.gradle.api.internal.changedetection.state.DefaultFileSystemSnapshotter.access$200(DefaultFileSystemSnapshotter.java:65)
at org.gradle.api.internal.changedetection.state.DefaultFileSystemSnapshotter$2.create(DefaultFileSystemSnapshotter.java:132)
at org.gradle.api.internal.changedetection.state.DefaultFileSystemSnapshotter$2.create(DefaultFileSystemSnapshotter.java:129)
at org.gradle.cache.internal.ProducerGuard$StripedProducerGuard.guardByKey(ProducerGuard.java:115)
at org.gradle.api.internal.changedetection.state.DefaultFileSystemSnapshotter.snapshot(DefaultFileSystemSnapshotter.java:129)
at org.gradle.api.internal.changedetection.state.DefaultFileSystemSnapshotter$FileCollectionVisitorImpl.visitCollection(DefaultFileSystemSnapshotter.java:258)
at org.gradle.api.internal.file.AbstractFileCollection.visitRootElements(AbstractFileCollection.java:282)
at org.gradle.api.internal.file.CompositeFileCollection.visitRootElements(CompositeFileCollection.java:206)
at org.gradle.api.internal.changedetection.state.DefaultFileSystemSnapshotter.snapshot(DefaultFileSystemSnapshotter.java:142)
at org.gradle.internal.fingerprint.impl.AbstractFileCollectionFingerprinter.fingerprint(AbstractFileCollectionFingerprinter.java:54)
at org.gradle.internal.fingerprint.impl.AbstractPathOnlyFileCollectionFingerprinter.fingerprint(AbstractPathOnlyFileCollectionFingerprinter.java:37)
at org.gradle.api.internal.changedetection.state.CacheBackedTaskHistoryRepository.fingerprintTaskFiles(CacheBackedTaskHistoryRepository.java:358)
... 34 more
Caused by: java.io.IOException: The process cannot access the file because another process has locked a portion of the file
at org.gradle.internal.hash.DefaultStreamHasher.doHash(DefaultStreamHasher.java:54)
at org.gradle.internal.hash.DefaultStreamHasher.hash(DefaultStreamHasher.java:38)
... 53 more
我缺少什么吗? 我正在Windows,Java 10.2,Gradle 4.10.1上运行它
答案 0 :(得分:0)
when reviewing the org.gradle.jvmargs
, it reads ...
destfile={someDirsHere}/build/jacoco/test-integration.exec
which will request exclusive access for writing that file; which locks it.
not passing the argument and using the default configuration should work:
task generateJacocoIntegrationTestKitProperties(type: GenerateJaCoCoTestKitProperties) {
destinationFile = file('integration.exec')
}
with a jacoco.gradle
(most likely) alike:
jacocoTestReport {
sourceSets sourceSets.main
executionData = files()
}
also see this gist, which appears relevant, concerning the aggregation of sub-project coverage tests:
subprojects.findAll { subproject ->
subproject.pluginManager.hasPlugin('java') && subproject.pluginManager.hasPlugin('jacoco')
}.each { subproject ->
executionData += subproject.tasks.jacocoTestReport.executionData
}
executionData = files(executionData.findAll {
it.exists()
})
for a single project, this makes little sense, but when having sub-projects, it does.