Gradle failed to clean output directory - java

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.

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.

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

Related

Though I have Java enabled in the server, I'm facing java path issue

I'm generating war file using Gradle using shell script but I'm getting the below error.
ls
cd ClaimCenter1003
javac -version
chmod 777 gwb.sh
./gwb.sh warTomcatDbcp
05-Jun-2020 13:22:54 ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
05-Jun-2020 13:22:54
05-Jun-2020 13:22:54 Please set the JAVA_HOME variable in your environment to match the
05-Jun-2020 13:22:54 location of your Java installation.
Java is set in all the bamboo servers though not working in many server through the console but when I triggered the build from command Line it is working fine.
The build is working in some servers giving me the output as I needed:
javac 1.8.0_161
build 05-Jun-2020 13:18:01 Downloading file:/opt/bamboo-agent-home/xml-data/build-dir/GUID-GCCA-VAR/ClaimCenter1003/gradle/wrapper/./gradle.zip
build 05-Jun-2020 13:18:02 .................................................................................
build 05-Jun-2020 13:18:04
build 05-Jun-2020 13:18:04 Welcome to Gradle 5.1.1!
build 05-Jun-2020 13:18:04
build 05-Jun-2020 13:18:04 Here are the highlights of this release:
build 05-Jun-2020 13:18:04 - Control which dependencies can be retrieved from which repositories
build 05-Jun-2020 13:18:04 - Production-ready configuration avoidance APIs
Build going through when did in CLI
CLI BUILD IMAGE
Please help me through this. Thank you
Either JAVA_HOME or PATH is not set on the build agents which fail.
If i were in your situation, I'd primarily take steps to ensure those exist.
An easy way would be to "dockerize" your build by simply using docker, e.g.:
docker run openjdk:{JDK_VERSION} bash `./buildscript.sh`.
The other way is to ensure java is installed correctly on your build agent prior to starting the actual build steps. The problem will be that it appears your build agent instance is reused by other builds, so even if this works it may cause other errors downstream, hence I recommend virtualization your build via docker.
I'd check if both $JAVA and $JAVA_HOME are correctly set and if not, to either explicitly install java (see for example https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/generic-linux-install.html to steps to install amazon coretto openjdk) or to set the environment variables manually if you're sure java exists on the target machine.

Could not determine java version from '13.0.1'

I have gradle 6.0.1 and JDK 13.0.1 installed and tried gradlew setupDecompWorkspace, but it tells me "Could not determine java version from '13.0.1' ". I've tried to find an answer for a week now and I can't find a solution.
edit: the result of gradlew setupDecompWorkspace --stacktrace: https://pastebin.com/NFqZpBkG
edit 2: i manually changed the wrapper.properties file and updated my gradle wrapper. Now gradlew setupDecompWorkspace --stacktrace gives me this:
https://pastebin.com/ubYj4Zq0
I installed jdk 13 and call react-native run-android, then get error above.
Solution:
Check if you have jdk 13 here: /Library/Java/JavaVirtualMachines/
ls /Library/Java/JavaVirtualMachines/
Then
cd /Library/Java/JavaVirtualMachines/
sudo rm -rf jdk-13.0.0 // your version
After that reinstall jdk-8 again.
Gradle didn't support Java 13 (without forking the compiler) until Gradle 6.0. You say that is the one you have installed, but you are not supposed to install anything when using the Gradle wrapper. Rather, the wrapper will download the version of Gradle that is defined in the gradle-wrapper.properties file.
If you run gradlew --version (and remember to use the 'w' version), there is a good chance you will see an older version. If so, either upgrade the wrapper with gradle wrapper --gradle-version 6.0.1 --distribution-type all (or newer), or downgrade Java.
I was having the same issue. 1.7.10 forge does not support gradle 6. In the \gradle\wrapper\gradle-wrapper.properties revert the gradle version to what it was before it is something like 4.x. (This is for 1.8.9 not 1.7.10 if it is 3.x maybe try JDK 7 instead of 8 if the same error occurs)
Gradle 4 does not support JDK 13. I am not sure what versions work for gradle 4 as I cannot find the documentation for the supported versions. After some trial and error, I found JDK 8 works. Download and install here.
After the installer is complete, it won't just work. You will need to set "JAVA_HOME". Go to your environment variabes (Control Panel\System and Security\System\Advanced system settings\Advanced\Environment Variables...) If "JAVA_HOME" doesn't exist in the system variables, create it. Call it "JAVA_HOME" and set the value to "C:\Program Files\Java\jdk1.8.0_241" if you used the installer I linked. After you have done this, click ok, ok, ok and close the control panel.
You are almost done! Now all you have to do is restart your computer and it should work. If it doesn't comment on this answer and # me. Hope it works.
Note: I recommend to use IntelliJ for modding and once you have decompiled, open the build.gradle with IntelliJ. Wait for it to load and then go back to your command prompt and type "gradlew genIntellijRuns" (as seen in github guide for modding)and now you are ready to start coding!

Failed to run tests in gradle project with error : 'Could not create the Java Virtual Machine'

I am trying to execute a test inside a gradle project.But when Itry to execute the tests using 'gradle test' in Intellij it fails .
what I have tried
create and build the project without error using 'gradle clean build'
open run configuration in intellij , select gradle , and create and execution with gradle task 'test'
execute newly created gradle run configuration
what I observe
gradle fails at task 'test' with error 'Error: Could not create the Java Virtual Machine.'
also gradle run never stops until I forcefully stop it
also it keep printing ' gradle executor 1(,2,3 and so on) executing , failed '
I am using java 9 , intellij , gradle .
I am running Kotlin project with gradle in IntelliJ.
------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------
Build time: 2019-02-08 19:00:10 UTC
Revision: f02764e074c32ee8851a4e1877dd1fea8ffb7183
Kotlin DSL: 1.1.3
Kotlin: 1.3.20
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Amazon.com Inc. 11.0.2+9-LTS)
OS: Mac OS X 10.14.3 x86_64
Getting similar issue, but to be specific:
Task :run FAILED
Unrecognized option: -d64
Error: Could not create the Java Virtual Machine.
...
To solve my issue, I basically had to select correct JDK for my IntelliJ.
To switch the Java runtime used to run IntelliJ IDEA:
On the Help menu, click Find Action, or press ⇧⌘A.
Find and select the Switch Boot JDK action.
Select the desired JDK and click OK.
Found this resource that helps! https://www.jetbrains.com/help/idea/tuning-the-ide.html
If by any chance you select a wrong JDK version, and the IDE not starting anymore, delete idea.jdk file: https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under?page=3

set JVM memory limit for Jhipster application started by Gradle bootRun

I have app generated by Jhipster (using gradle).
The problem of setting JVM options -Xmx -Xms is specific when app started from gradle (bootRun).
I was looking for solution in stackoverflow and tried many advices from forums .... but none worked for me. Java application took a lot of memory.
In the case of more microservices (more JVMs) Java consumes so much memory that it is unusable.
I tried many options like
modify build.gradle
set options from command line
use environment variable
.... but gradle ignored it always.
using gradle ver:
gradlew --version
Gradle 4.9
Build time: 2018-07-16 08:14:03 UTC
Revision: efcf8c1cf533b03c70f394f270f46a174c738efc
Kotlin DSL: 0.18.4
Kotlin: 1.2.41
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM: 1.8.0_172 (Oracle Corporation 25.172-b11)
OS: Linux 4.9.0-6-amd64 amd64
Limiting memory for Jhipster app works fine if starting apps as docker container.
It is possible to set heap size parameters by specifying them in Gradle script in bootRun as jvmArgs list elements.
You may do it in gradle/profile_dev.gradle file like this:
bootRun {
jvmArgs = ['-Xms256m', '-Xmx512m']
}
Possibly bootRun is already in file in the generated project, so just add jvmArgs... in the new line there.
Then it is possible to check on the metrics page if it has been properly set
(http://localhost:8080/admin/metrics)

why is my gradle build failing but gradlew build is successsful?

I have a gradle project that I am trying to build.
when I execute gradle clean build, it fails with the following error message
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':FacebookUpdateDependencies'.
> Could not resolve all dependencies for configuration ':compiler'.
> Could not resolve com.company.facebook:compiler:1.2+.
Required by:
::1.0
> Could not resolve com.company.facebook:compiler:1.2+.
> Failed to list versions for com.company.facebook:compiler.
> Unable to load Maven meta-data from http://mycompanynexus/compiler/maven-metadata.xml.
> Could not GET 'http://mycompanynexus/compiler/maven-metadata.xml'. Received status code 500 from server: Internal Server Error
However, when I tried
./gradlew clean build the build is successful.
why the build fails in the former and not the latter?
here is revelant portion of build.gradle
task wrapper(type: Wrapper) {
gradleVersion = '2.11'
}
EDIT
local$: gradle -v
------------------------------------------------------------
Gradle 2.13
------------------------------------------------------------
Build time: 2016-04-25 04:10:10 UTC
Build number: none
Revision: 3b427b1481e46232107303c90be7b05079b05b1c
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.7.0_79 (Oracle Corporation 24.79-b02)
OS: Mac OS X 10.11.1 x86_64
local$ ./gradlew -v
------------------------------------------------------------
Gradle 1.12
------------------------------------------------------------
Build time: 2014-04-29 09:24:31 UTC
Build number: none
Revision: a831fa866d46cbee94e61a09af15f9dd95987421
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
Ivy: 2.2.0
JVM: 1.7.0_79 (Oracle Corporation 24.79-b02)
OS: Mac OS X 10.11.1 x86_64
I just noticed that the wrapper version is 1.12 and not 2.12. That is, there is a very large version difference between the wrapper and the installed version of gradle. There have probably been many incompatible changes to the different gradle plugins over the last 2 years, which may lead to the build problems you observe.
As already mentioned the gradle wrapper is a separate version of gradle that resides in the gradle/wrapper folder of your project. The wrapper is only built/updated, when executing the wrapper task in your project (gradle wrapper). That is your project's wrapper has not been updated for the last 2 years or has been created with the wrong version initially (1.12 instead of 2.11).
Given the above it's hard the tell what is actually causing the build to fail - apart from the incompatibilities between gradle 1.12 and 2.13. But this version mismatch is probably the root cause of your problem.
Most likely your project won't built anymore using the wrapper once you regenerated the wrapper with version 2.11 (the version mentioned in the build file), as 2.11 is likely to be incompatible to 1.12 as well...
This tells you that your Gradle version 2.11 will be used when gradlew command is invoked instead of the one installed on system. Always run gradlew command as it ensures your build is run against the gradle version it is supposed to, you are never required to install the correct version of gradle and really speeds up the build time.
Here is an excerpt from Gradle Wrapper definition:
Most tools require installation on your computer before you can use them. If the installation is easy, you may think that’s fine. But it can be an unnecessary burden on the users of the build. Equally importantly, will the user install the right version of the tool for the build? What if they’re building an old version of the software?
The Gradle Wrapper (henceforth referred to as the “Wrapper”) solves both these problems and is the preferred way of starting a Gradle build.
If a Gradle project has set up the Wrapper (and we recommend all projects do so), you can execute the build using one of the following commands from the root of the project:
./gradlew (on Unix-like platforms such as Linux and Mac OS X)
gradlew (on Windows using the gradlew.bat batch file)
Each Wrapper is tied to a specific version of Gradle, so when you first run one of the commands above for a given Gradle version, it will download the
corresponding Gradle distribution and use it to execute the build.

Categories