Unable to delete build dir after running Sonar - sonarqube

I am using the SonarQube Gradle plugin version 3.0 with Gradle 6.7.1 for analysis of my Java code. This works fine and the results are uploaded to Sonar. When I do gradlew clean test sonarqube initially I have no problem. But when I run it subsequently I get the following:
java.io.IOException: Unable to delete directory 'C:\xxx\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:\xxx\build\sonar\findbugs\findsecbugs-plugin.jar
- C:\xxx\build\sonar\findbugs
- C:\xxx\build\sonar
This keep on failing until I kill the Gradle daemon after which I can successfully run sonarqube again.
Is there a way to get around this?

Related

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
*** 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>
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.
Just rename the " build " folder.
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.
For me the files where under a different user and the group and the permissions were not sufficient to write to the files of the directory in question.
Try checking who the user of the project files are with ls -al
If the project and the sub directories and files are under a different user. You can run sudo chown -R [new_owner] [project_folder_name] The flag -R here recursively changes owner for the sub files and sub dirs.
You can also add additional permissions to the group (if the user belongs to the group) or even change the group (if the user does not belong to the group). The basic idea is giving the user enough permission (rwx) to use files.
In Windows 10 Kill all Java TM instances by running this command on command prompt :
TASKKILL /F /IM java.exe
Or you delete your app installed on your phone and reinstall it again.This solved my problem
As I have faced similar kinds of errors during the flutter app development, I have figured out which process is blocking the running app. So I have just ended Open JDK from the Process list and then retried running the app without debug mode and it's working. The thing I learned here is that we have multiple development environments running in the background so we have to determine which process is blocking others.
Delete build folder in this path : your project\app . Then rebuild project.
If you are running windows 10, Go to task manager and end the following task
.......................
Java Platform SE binary
There might be more than one above mentioned task just end all of them and rebuild works
I went to my file system and deleted the file manually. Restarted my android

Bamboo build error: How to properly clean bamboo caches?

The problem:
Bamboo executes old unit tests that don't exist my current develop branch which causes a build error.
The situation that causes this problem:
After a big refactoring process of my maven java project, where I basically moved, modified and renamed every file, I committed my changes to my remote repository.
That triggered my bamboo build plan, to start the build process.
The git code checkout seems to work, but the next step, running the unit tests, fails!
Looking in the log file I see that an old, no more existing java Unit test class gets executed and of course fails because of NullPointerExceptions.
Things I tried to fix this problem
A. Remove caches in the Administration section
I went to Bamboo->Administration->Repository Settings and selected
the cache of my project and deleted it.
I started the build plan again
BUILD ERROR ! Same problem
B. Delete the cache directory in the file system
Start a RDP session on the bamboo server
stop bamboo
go to D:\bamboo-home_64\xml-data\build-dir_git-repositories-cache
delete all files in this folder
start bamboo
start the build plan again
BUILD ERROR! same problem
Meta info
bamboo version: 6.1.0 build 60103 - 18 Jul 17
I don't know what I can do to fix this..
There's Clean working directory task. Add it as first task to your Job and see if it solves the issue.

Go CI does not recognize build file for gradle

I have setup GO CI pipeline for continuous integration in my project. I tried to add a project that is built using gradle. I tried a add gradle task for building my application.
While executing build it shows that
FAILURE: Build failed with an exception.
* What went wrong:
Task 'build' not found in root project 'Gradlepipelinejob'.
I tried to add defaultTasks 'clean', 'compile' to the parent build.gradle file. But still the same error exists. Someone pls help me in resolving this issue.
I think 'build' should be in Command section, rather than arguments. Even after that if it doesn't works, try executing build commands in the agent terminal(or any command prompt).This will let you figure out whether the error is in server or agent.
GO CI runs the command in the code checkout directory so please check if your gradle file is present or not in that directory

How to use/start the gradle daemon on a Mac?

Every time I execute a gradle command on Mac I get a message saying:
"This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.10/userguide/gradle_daemon.html"
I've created a gradle.properties file with the line org.gradle.daemon=true as mentioned in the web page given in the message. However no matter what I do, I still continue to get that message.
If I execute the command
gradle --daemon
then it executes successfully, but still next time I do something I get that message about it could be faster and builds are just as slow as before I started the daemon.
My installation directory is no /Users/username as in gradle_daemon.html as I'm falling a Udacity course (https://www.udacity.com/course/viewer#!/c-ud867/) and they recommend installing it to /usr/local/gradle
How can I actually get the gradle dameon to work and get rid of that could be faster message?
(Using Gradle version 2.10)
just put
org.gradle.daemon=true
in the ~/.gradle/gradle.properties file. Then each build on your machine will use the gradle wrapper and the message dissapears.
The page doesn't say anywhere that gradle must be installed in /Users/username. It says that this directory is your home directory, and that's where the .gradle/gradle.properties file must be located. The place where gradle is installed is irrelevant.

sonar-pdfreport-plugin-1.4 with Sonar 4.5.1

I am using Sonar 4.5.1 and sonar-pdfreport-plugin-1.4 to run the build. PDF report is not getting generated an is showing below message : Internal error: Can't retrieve project info. Parent project node is empty. Authentication?.
I saw a bug posted for this (https://jira.sonarsource.com/browse/SONARPLUGINS-3854) but would like to know what is the workaround available for this issue. User Authentication is already set for this in General Settings->Pdf report but doesn't work either.
This issue has been fixed in commit a49b8f61afbf47b5f7976d0a759cb0efcd6c5bce.
For now you cannot download jar with this fix, but you can download sources and build custom version:
fetch sources (by git clone https://github.com/SonarQubeCommunity/sonar-pdf-report.git or download zip)
execute maven command mvn clean install
copy generated jar to sonar/data/extensions/plugins

Resources