gpt4 book ai didi

gradle - Gradle + TestKit + JaCoco:文件锁定异常

转载 作者:行者123 更新时间:2023-12-03 03:58:22 25 4
gpt4 key购买 nike

我正在尝试将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上运行它

最佳答案

查看org.gradle.jvmargs时,它显示为...

destfile={someDirsHere}/build/jacoco/test-integration.exec

这将要求以独占方式访问该文件;锁定它。

不传递参数并使用默认配置应该起作用:
task generateJacocoIntegrationTestKitProperties(type: GenerateJaCoCoTestKitProperties) {
destinationFile = file('integration.exec')
}

jacoco.gradle(最有可能)类似:
jacocoTestReport {
sourceSets sourceSets.main
executionData = files()
}

另请参阅此 gist,它看起来很相关,涉及子项目覆盖率测试的汇总:
subprojects.findAll { subproject ->
subproject.pluginManager.hasPlugin('java') && subproject.pluginManager.hasPlugin('jacoco')
}.each { subproject ->
executionData += subproject.tasks.jacocoTestReport.executionData
}

executionData = files(executionData.findAll {
it.exists()
})

对于单个项目,这没有什么意义,但是当拥有子项目时,它确实可行。

关于gradle - Gradle + TestKit + JaCoco:文件锁定异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52392985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com