2

Issue Description
Running "gradle clean" failed to artifacts from project output directory. After enable --stacktrace I can see below error

Caused by: org.gradle.api.file.UnableToDeleteFileException: Unable to delete file: C:\Users\xxxx\my-project-root\build\libs\some.jar

Here is my "gradle --version" output

------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------

Build time:   2019-01-10 23:05:02 UTC
Revision:     3c9abb645fb83932c44e8610642393ad62116807

Kotlin DSL:   1.1.1
Kotlin:       1.3.11
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_152 (Oracle Corporation 25.152-b16)
OS:           Windows 10 10.0 amd64

Initially my thought process was that some gradle daemon might be still be holding a reference to build artifacts. But after running "gradle --stop" I still get the same error for clean task.

Do note that if I open command prompt/powershell with administrative mode ":clean" tasks works fine.

I am not sure if anyone has faced this strange issue.

Solution
Please suggest if any.

3
  • Probaly JAR is used somewehere Commented Feb 2, 2019 at 0:01
  • 4
    Is it possible you compiled once as Administrator earlier? It would have generated that file and your normal user may not have permission to it. I'd expect that after a gradle clean and gradle --stop as Administrator you would be able to compile as a normal user. Commented Feb 5, 2019 at 5:53
  • @EricAnderson This solution actually works. Thanks a lot!! Commented Feb 5, 2019 at 21:19

2 Answers 2

2

As mentioned by Eric Anderson in this comment:

Is it possible you compiled once as Administrator earlier? It would have generated that file and your normal user may not have permission to it. I'd expect that after a gradle clean and gradle --stop as Administrator you would be able to compile as a normal user.

I ran into this same problem after having done sudo gradle run earlier, and a sudo gradle clean fixed it.

Sign up to request clarification or add additional context in comments.

Comments

0

The file is likely open by another process. The easiest way to find the process keeping the file open is to use Process Explorer and "Find a Handle or DLL". Search for the file name. Then close the processes listed.

If you prefer a command-line tool, execute handle like:

handle c:\path\to\file

1 Comment

Tried both of the above mentioned approach. Process Explorer says "0 matching items". And Handler says "No matching handlers found". Also i cant even delete it using windows del or rm(MINGW) . I got "Access is denied"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.