Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle can’t delete build folders #29011

Closed
pisfer opened this issue May 1, 2024 · 7 comments
Closed

Gradle can’t delete build folders #29011

pisfer opened this issue May 1, 2024 · 7 comments
Labels
closed:invalid Not applicable to Gradle or EOL version

Comments

@pisfer
Copy link

pisfer commented May 1, 2024

Current Behavior

I have this problem with my Kotlin project. Gradle sometimes gives me an error when trying to build the project. It says it can’t delete some build folders. I can delete them manually, I also tried to use gradlew --stop command and TASKKILL /F /IM java.exe however none of them did anything. The error persists until I manually delete those folders. Also in my project, I have 1 additional module and a buildSrc module for the Gradle plugin (an error was present before this plugin). I have this error in the build folders of all 3 modules randomly.

Expected Behavior

No errors

Context (optional)

Now I have to delete build folders every time I get the error.

Steps to Reproduce

The structure of my project:
scr3

I have 3 modules: main one, buildSrc, and TelegramLib. The error was first seen when I included TelegramLib. Now the problem usually starts in the build folder of buildSrc. Firstly I see the error about buildSrc then I delete the folder, then I see a mistake with TelegramLib where I also need to delete a folder, and finally, the main build folder also needs to be deleted manually. I have not noticed a pattern, so it seems to be random when It gives an error and when it does not.

Here is my gradle.kts file for buildSrc:

plugins {
    kotlin("jvm") version "1.9.22"
    `kotlin-dsl`
}
repositories {
    mavenCentral()
}
dependencies {
    testImplementation(kotlin("test"))
    runtimeOnly(gradleApi())
}
tasks.test {
    useJUnitPlatform()
}
kotlin {
    jvmToolchain(17)
}

gradle.kts file for TelegramLib:

plugins {
    kotlin("jvm")
}
group = "com.github.kotlintelegrambot"
version = "0.0.1"
repositories {
    mavenCentral()
}
dependencies {
    ...
}
tasks.test {
    useJUnitPlatform()
}
kotlin {
    jvmToolchain(17)
    compilerOptions {
        freeCompilerArgs.add("-Xcontext-receivers")
    }
}

gradle.kts file for Main:

plugins {
    kotlin("jvm") version "1.9.23"
    id("io.ktor.plugin") version "2.3.9"
    id("org.jetbrains.kotlin.plugin.serialization") version "1.9.23"
}
apply<CustomPlugin>()

kotlin {
    jvmToolchain(17)
    compilerOptions {
        freeCompilerArgs.add("-Xcontext-receivers")
    }
}
group = "com.bot"
version = "0.0.1"
repositories {
    mavenCentral()
}
dependencies {
    ...
}

Gradle version

Gradle 8.7

Gradle version that used to work

Build scan URL (optional)

https://scans.gradle.com/s/flhksq3rwyziw

Your Environment (optional)

Kotlin: 1.9.22
OS: Windows 11 10.0 amd64

@pisfer pisfer added a:regression This used to work to-triage labels May 1, 2024
@ov7a
Copy link
Member

ov7a commented May 1, 2024

We appreciate the effort, but we must ask for more information so that we can triage it.

We do not see an immediate root cause, and we need a minimal reproducible example for the triage. If we have a reproducer, we may be able also to suggest workarounds or ways to avoid the problem.

The ideal way to provide a reproducer is to leverage our reproducer template. You can also use Gradle Project Replicator to reproduce the structure of your project.

This issue will be closed after 7 days unless you provide more information.


Please also clarify why you marked this issue as a regression. Which version of Gradle works for you?

@ov7a ov7a added the pending:reproducer Indicates that the issue requires a reproducer or will be closed after 7 days label May 1, 2024
@pisfer
Copy link
Author

pisfer commented May 2, 2024

Thank you for your help! I marked this issue as a regression by mistake.
I tried to use Gradle Project Replicator, however when I try to build my project after I add initscript/init.gradle into my build.gradle.kts it says it "Plugin with id 'com.android.gradle.replicator.ProjectReplicatorPlugin' not found." But, I did run gradlew publishLocal on that plugin and I can see it in m2/repository folder.

Here is what I included in my build.gradle.kts file:

buildscript {
    repositories {
        repositories {
            mavenLocal()
            mavenCentral()
        }
        dependencies {
//            classpath("com.android.gradle.replicator:project-replicator:0.2") <- this did not work, so I just used direct path
            classpath(files("path\\to\\.m2\\repository\\com\\android\\gradle\\replicator\\project-replicator\\0.2\\project-replicator-0.2.jar"))
        }
    }
}
allprojects {
    apply(plugin = "com.android.gradle.replicator.ProjectReplicatorPlugin")
}

@github-actions github-actions bot removed the pending:reproducer Indicates that the issue requires a reproducer or will be closed after 7 days label May 2, 2024
@pisfer
Copy link
Author

pisfer commented May 2, 2024

I succeded at applying the plugin. Although it was still a bit strange, I had to add implementation("com.android.gradle.replicator:project-replicator:0.2") to my project dependency and use

allprojects {
    apply { plugin(com.android.gradle.replicator.ProjectReplicatorPlugin::class) }
}

I also noticed that this "Unable to delete directory" error appears after I change some code in buildSrc. Usually gradle can't delete build folder of "TelegramLib" after the change.

The json file:
project-structure.json

@ov7a ov7a added a:bug and removed a:regression This used to work labels May 3, 2024
@ov7a
Copy link
Member

ov7a commented May 3, 2024

@pisfer can you provide the reproducer project, please? Leveraging our reproducer template would be the best option.

Do you have some insights on what process prevents Gradle from deleting a file?

@ov7a ov7a added the pending:reproducer Indicates that the issue requires a reproducer or will be closed after 7 days label May 3, 2024
@pisfer
Copy link
Author

pisfer commented May 4, 2024

Here is a link for the reproducer project: https://github.com/pisfer/gradle-issue-29011-reproducer

And I tried to check which process holds a lock on those files that gradle can't delete, I did not find any locks.

Also I noticed that a problem disappeared when I removed:
include("TelegramLib") from settings.gradle.kts
And
implementation(project(":TelegramLib")) from build.gradle.kts

@github-actions github-actions bot removed the pending:reproducer Indicates that the issue requires a reproducer or will be closed after 7 days label May 4, 2024
@pisfer
Copy link
Author

pisfer commented May 4, 2024

I found the problem. It was Google Drive for Desktop that locked those files.
Or at least it works right now after I disabled gdrive. Anyway, thank you for your help.

Also, Is it possible to tell Gradle not to recompile the whole project if the buildSrc source code was changed?

@ov7a
Copy link
Member

ov7a commented May 6, 2024

It was Google Drive for Desktop that locked those files.

Okay, so the problem was caused by the environment. Closing the issue since it's not something that should be fixed in Gradle.

Also, Is it possible to tell Gradle not to recompile the whole project if the buildSrc source code was changed?

You can refactor your buildSrc login into a plugin and enable the configuration cache. For more details, refer to this doc

@ov7a ov7a closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2024
@ov7a ov7a added closed:invalid Not applicable to Gradle or EOL version and removed a:bug to-triage labels May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed:invalid Not applicable to Gradle or EOL version
Projects
None yet
Development

No branches or pull requests

2 participants