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

我仔细地try 了所有的建议,但没有一个能解决我的问题.我只有在重启Windows并只工作一次的情况下才能让它恢复工作.

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-在windows中以管理员身份运行android studio对我来说很有用.

这是我的楼房.格雷德

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'
    }
}

格雷德尔.属性

micronautVersion=2.1.3
kotlinVersion=1.4.10

and the build folder seen in IntelliJ

enter image description here

*已编辑

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> 

推荐答案

问题是,您有多个Gradle进程仍在锁定您的文件.

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

如果你看到了什么,那可能是个问题.

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.

发生这种情况的另一个例子是,我用ProcessBuilder启动另一个Java进程,但它没有退出.

Kotlin相关问答推荐

Kotlin是否针对范围和进度优化sum()?

Android Jetpack编写androidx.compose.oundation.lazy.grid.Items

在Kotlin中,我是否可以访问已知的WHEN子句值?

数据流弹性模板失败,出现错误&未知非复合转换urn";

两个LocalDateTime之间的Kotlin差异

ActivityResultContracts TakePicture 结果总是返回 false

如何在 kotlin 中创建自定义迭代器并添加到现有类?

找不到引用的类 kotlin.internal.annotations.AvoidUninitializedObjectCopyingCheck

如何在 kotlin @Parcelize 中使用 null

Fragment的onDestroy()中是否需要将ViewBinding设置为null?

Kotlin 类的调用方法

TextField maxLength - Android Jetpack Compose

为什么 Kotlin Pair 中的条目不可变?

Kotlin的web-framework框架

如何使用kotlin中的反射查找包中的所有类

在 gradle android library kotlin 项目中禁用 META-INF/* 生成

如何在Kotlin中获得KType?

Kotlin:如何从另一个类访问字段?

TornadoFX 中设置 PrimaryStage 或 Scene 属性的方法

从 java 活动 *.java 启动 kotlin 活动 *.kt?