Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory

For some unknown reason, whenever I run gradle clean build after I start my notebook it works as expected. When I try for the second time, I always get

Unable to delete directory 'C:\_d\mycompany\WSs\demo\build'
  Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory.
  - C:\_d\mycompany\WSs\demo\build\classes\kotlin\main\com\mybank
  - C:\_d\mycompany\WSs\demo\build\classes\kotlin\main\com
  - C:\_d\mycompany\WSs\demo\build\classes\kotlin\main
  - C:\_d\mycompany\WSs\demo\build\classes\kotlin\test\com
  - C:\_d\mycompany\WSs\demo\build\classes\kotlin\test
  - C:\_d\mycompany\WSs\demo\build\classes\kotlin
  - C:\_d\mycompany\WSs\demo\build\classes
  - C:\_d\mycompany\WSs\demo\build\generated\source\kapt
  - C:\_d\mycompany\WSs\demo\build\generated\source\kaptKotlin\main
  - C:\_d\mycompany\WSs\demo\build\generated\source\kaptKotlin\test
  - C:\_d\mycompany\WSs\demo\build\generated\source\kaptKotlin
  - C:\_d\mycompany\WSs\demo\build\generated\source
  - C:\_d\mycompany\WSs\demo\build\generated
  - C:\_d\mycompany\WSs\demo\build\kotlin\compileKotlin\caches-jvm\inputs
  - C:\_d\mycompany\WSs\demo\build\kotlin\compileKotlin\caches-jvm\jvm\kotlin
  - C:\_d\mycompany\WSs\demo\build\kotlin\compileKotlin\caches-jvm\jvm
  - and more ...
  New files were found. This might happen because a process is still writing to the target directory.
  - C:\_d\mycompany\WSs\demo\build\kotlin\compileKotlin

I found someone failing quite similar problem but using Android Studio/Ubuntu (I am using IntelliJ Community/Windows 10): other question

I tried carefully all recommendations and none of them fixed my issue. I only get it working back if I restart my Windows and just work one time.

Some of the recommendations are:

1 - Close the studio and go to the path the issue is located at and delete the folder there. I tried close IntelliJ and I can't delete the folder straight

2 - File > Settings > Build, Execution, Deployment > Instant Run > Uncheck this Check box (Enable Instant Run to hot swap code) There is no such optional in my IntelliJ

IntelliJ IDEA 2020.2.3 (Community Edition)
Build #IC-202.7660.26, built on October 6, 2020
Runtime version: 11.0.8+10-b944.34 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 1963M
Cores: 8
Non-Bundled Plugins: Lombook Plugin, org.jetbrains.kotlin

3 - gradlew clean Same issue

4 - right-click on the directory, click properties on the context menu that will appear, then uncheck the "Read Only" attribute. After that, click the "Apply" to apply changes. I am administrator but I couldn't change such folder attribute.

5 - Running android studio as administrator in windows worked for me. Same issue

Here are my build.gradle

plugins {
    id "org.jetbrains.kotlin.jvm" version "1.4.10"
    id "org.jetbrains.kotlin.kapt" version "1.4.10"
    id "org.jetbrains.kotlin.plugin.allopen" version "1.4.10"
    id "com.github.johnrengelman.shadow" version "6.1.0"
    id "io.micronaut.application" version '1.0.5'
    id "com.gorylenko.gradle-git-properties" version "2.2.2"
}

version "0.1"
group "com.mybank"

repositories {
    mavenCentral()
    jcenter()
}

micronaut {
    runtime "netty"
    testRuntime "junit5"
    processing {
        incremental true
        annotations "com.mybank.*"
    }
}

dependencies {
    implementation("io.micronaut:micronaut-validation")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
    implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
    implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
    implementation("io.micronaut:micronaut-runtime")
    implementation("javax.annotation:javax.annotation-api")
    implementation("io.micronaut:micronaut-http-client")

    implementation("io.micronaut:micronaut-management")
    implementation("io.micronaut.sql:micronaut-jdbc-hikari")
    implementation("io.micronaut.sql:micronaut-hibernate-jpa")
    runtimeOnly("com.h2database:h2")
    runtimeOnly("ch.qos.logback:logback-classic")
    runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")



}

mainClassName = "com.mybank.ApplicationKt"
java {
    sourceCompatibility = JavaVersion.toVersion('11')
}

compileKotlin {
    kotlinOptions {
        jvmTarget = '11'
    }
}
compileTestKotlin {
    kotlinOptions {
        jvmTarget = '11'
    }
}

gradle.properties

micronautVersion=2.1.3
kotlinVersion=1.4.10

and the build folder seen in IntelliJ

enter image description here

*** edited

I didn't find how fix it. Now is happening with a project I have just cloned from micronaut

And I can't delete build folder although I am Windows administrator

PS C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin> gradle clean build
> Task :clean FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':clean'.
> java.io.IOException: Unable to delete directory 'C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build'
    Failed to delete some children. This might happen because a process has files open or has its working directory set in 
the target directory.
    - C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build\generated\source\kaptKotlin\main
    - C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build\generated\source\kaptKotlin\test
    - C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build\generated\source\kaptKotlin
    - C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build\generated\source
    - C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build\generated
    - C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build\tmp\kapt3\incApCache\main
    - C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build\tmp\kapt3\incApCache\test
    - C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build\tmp\kapt3\incApCache
    - C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build\tmp\kapt3\stubs\main
    - C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build\tmp\kapt3\stubs\test
    - C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build\tmp\kapt3\stubs
    - C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build\tmp\kapt3
    - C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin\build\tmp

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 13s
1 actionable task: 1 executed
PS C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin> gradle stop

FAILURE: Build failed with an exception.

* What went wrong:
Task 'stop' not found in root project 'hello-world-kotlin'.

* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or 
--debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2s
PS C:\_d\toLearn\micronaut-grpc\examples\hello-world-kotlin> 
like image 362
Jim C Avatar asked Nov 08 '20 03:11

Jim C


2 Answers

The problem is that you have multiple Gradle processes that are still holding locks to your files.

You can try running gradle --stop when this happens to stop any daemons that are running in the backgorund (this usually helps).

You can also check the state of your daemons by running gradle --status. For me this outputs:

No Gradle daemons are running.

Only Daemons for the current Gradle version are displayed.
See https://docs.gradle.org/6.5/userguide/gradle_daemon.html#sec:status

If you see something there it might be a problem.

Using --no-daemon and --no-parallel might help, but they would just hide the underlying problem.

In my case when this happened I realized that I had processes running in the background because of tests never finishing. Check all your threading and/or coroutine usage for unclosed / unfinished processes.

One other case when this happened to me is when I was using ProcessBuilder to start another Java process and it didn't exit.

like image 142
Adam Arold Avatar answered Oct 06 '22 09:10

Adam Arold


In my case, I experienced this error after I ran a Gradle command as the root user in Linux.

After switching back to a regular user, Gradle gave me the above error. When I tried to remove the build directory using rm -rf build/, I received a "Permission denied" error. You can solve this problem by removing the build directory as the root user.

like image 3
Ferhad Mehdizade Avatar answered Oct 06 '22 10:10

Ferhad Mehdizade