Gradle Clean无法删除依赖的jar

时间:2019-05-22 08:33:59

标签: java gradle

我有一个多模块Gradle 4.4项目-有一个父级build.gradle,然后有两个子级Gradle项目,每个项目都有自己的build.gradle。两者都是Java项目(一个用于开发代码,另一个用于QA)。开发项目是质量检查项目的依赖项(我在质量检查项目的testCompile project(':dev-project')中有build.gradle)。否则,build.gradle文件中没有任何有趣或异常的东西,它们会导入java插件和com.github.johnrengelman.shadow

如果我尝试连续两次构建父项目(没有打开IDE,在没有管理员权限的情况下从Git Bash运行./gradlew clean build),构建将失败:

09:55:24.449 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Execute clean for :dev-project:clean'
09:55:24.449 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Removed task artifact state for {} from context.
09:55:24.450 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':dev-project:clean'
09:55:24.450 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] :dev-project:clean FAILED
09:55:24.451 [WARN] [org.gradle.api.Project] :dev-project:clean took 1587ms
09:55:24.451 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Task :dev-project:clean'
09:55:24.451 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Task :dev-project:clean' completed
09:55:24.452 [INFO] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] :dev-project:clean (Thread[Task worker for ':',5,main]) completed. Took 1.588 secs.
09:55:24.452 [DEBUG] [org.gradle.internal.work.DefaultWorkerLeaseService] Worker lease root.1.14 completed (1 worker(s) in use)
09:55:24.452 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Task worker for ':': released lock on root.1.14
09:55:24.452 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Task worker for ':': released lock on :
09:55:24.452 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] Task worker [Thread[Task worker for ':',5,main]] finished, busy: 1.588 secs, idle:     0.002 secs
09:55:24.453 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] Task worker [Thread[Daemon worker Thread 3,5,main]] finished, busy: 0.0 secs, idle:     1.59 secs
09:55:24.453 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] Task worker [Thread[Task worker for ':' Thread 2,5,main]] finished, busy: 0.0 secs,     idle: 1.591 secs
09:55:24.454 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] Task worker [Thread[Task worker for ':' Thread 3,5,main]] finished, busy: 0.0 secs,     idle: 1.592 secs
09:55:24.455 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Run tasks'
09:55:24.456 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
09:55:24.456 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
09:55:24.456 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
09:55:24.456 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
09:55:24.456 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task 'dev-project:clean'.
09:55:24.456 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Unable to delete file:     C:\workspace\parent-project\dev-project\libs\dev-project-0.1.0.jar
09:55:24.457 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
09:55:24.457 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try:
09:55:24.457 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  Run with --scan to get full insights.
09:55:24.457 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
09:55:24.457 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Exception is:
09:55:24.457 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task     ':dev-project:clean'.
09:55:24.457 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(    ExecuteActionsTaskExecuter.java:100)
09:55:24.457 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(    ExecuteActionsTaskExecuter.java:70)
09:55:24.458 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at     org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
09:55:24.458 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(    SkipUpToDateTaskExecuter.java:62)

我怀疑dev-project JAR不能删除,因为它受QA项目的依赖,因此Gradle对其保持了某种锁定状态。

如果我在Windows任务管理器中删除了Java(TM) Platform SE Binary进程,则可以成功构建,但是我希望它是自动的。

1 个答案:

答案 0 :(得分:0)

此错误是由Gradle守护程序引起的-构建完成后,它仍在后台运行,并且由于某种原因在dev-project jar上保持锁定。

org.gradle.daemon=false添加到我的全局gradle.properties文件中已解决了该问题,尽管以稍微慢一些的构建为代价。

我在Gradle团队中有raised an issue,并且如果有任何疑问,将会更新此答案。