I'm trying to run multiple 'gradle installdebug' commands in parallel using a java program using multiple threads. Basically, this is to compile multiple pre-written android apps together in parallel as those apps are not dependent on each other. But all other gradle commands waits with the message 'busy Daemons could not be reused' until the first command completes its execution. I need help in running all the gradle command independently at the same time. more details below.
I have 10 android app folders in windows 10 machine and my java program goes into each of this app folder and executes 'gradle installdebug' command. This happens in parallel using multiple threads. This command compiles android app into APK and install it to the running android emulator. All of the 10 commands get executed successfully and the APKs are installed as expected. The problem I'm facing is that the 9 gradle jobs are queued until the first one is finished, and then remaining 9 gradle jobs runs in parallel. I tried to run the same gradle commands with .Net c# code too, but same issue is observed. I believe this is not a multithreading issue from java code or c# code, instead it is a gradle configuration issue. Looks like I'm missing something while forming the gradle command or configuring the gradle either globally or in the android app gradle settings files.
I'm using the gradle 7.5.1 offline version that I extracted into C: drive for the gradle binary/command as the android app have no dependencies to download while compiling. At end of the question, I provided the android gradle settings files too.
This is the command that I execute from the code.
cmd.exe /c C:\gradle-7.5.1-bin\bin\gradle installdebug
Starting a Gradle Daemon (subsequent builds will be faster)
Task :preBuild UP-TO-DATE
Task :javaPreCompileDebug
Task :mergeDebugResources
and goes on....
Initially for few tasks it runs in parallel with above output then for rest of the commands the gradle outputs the following messages and waits. In this example, from the 7th command it starts queuing. But If I run the program again, only one gradle command gets the daemon, rest all gets queued. On multiple runs the busy daemons count keeps increasing even beyond 100s.
Starting a Gradle Daemon, 6 busy Daemons could not be reused, use --status for details
[ My Note: here it waits for the first gradle command to finish, then this continues. same for the rest of the 8 commands ]
Task :preBuild UP-TO-DATE
Task :javaPreCompileDebug
Task :mergeDebugResources
and goes on....
I tried the command with --no-daemon as shown below.
cmd.exe /c C:\gradle-7.5.1-bin\bin\gradle --offline --no-daemon --build-cache installdebug
With this command I don't see the 'busy Daemons could not be reused' message, but it is slow as for each command a single Daemon started and stopped as shown in below output. Also, this is still having the same problem of waiting for the first command to be complete before running other commands for other android apps.
To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.5.1/userguide/gradle_daemon.html#sec:disabling_the_daemon.
Daemon will be stopped at the end of the build
[ My Note: here it waits for the first gradle command to finish, then this continues. same for the rest of the 8 commands ]
> Task :preBuild UP-TO-DATE
> Task :javaPreCompileDebug
and goes on....
I have no idea why the other 9 gradle commands are waiting until the first one finished as there is no dependency between them because each of these commands are executed in separate android app folders.
To provide more info, the following is the "build.gradle" file the each of those 10 android apps has.
plugins {
id 'com.android.application'
}
android {
namespace "com.example.simple.myapp1"
compileSdk 31
defaultConfig {
applicationId "com.example.simple.myapp1"
minSdk 30
targetSdk 31
versionCode 1
versionName "1.0"
}
signingConfigs {
aerndappsigning {
keyAlias 'androiddebugkey'
keyPassword 'android'
storeFile file('platform.jks')
storePassword 'android'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.aerndappsigning
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
}
the following is the "gradle.properties" file in the android app.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
android.enableJetifier=true
android.nonTransitiveRClass=true
org.gradle.daemon=true
org.gradle.parallel=true
the following is the "local.properties" file in the android app.
sdk.dir=D\:\\AndroidSdk
finally, the following is the "settings.gradle" file in the android app.
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
plugins {
id 'com.android.application' version '7.1.0-alpha11'
id 'com.android.library' version '7.1.0-alpha11'
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "myapp1"
include ':app'
Before posting this question, I searched solutions online, landed up on many posts having similar output, but nothing helped as none of those use cases is similar to what I explained above like running the command in parallel in multiple threads.
The other suggested solutions I tried and their outcomes is as follows:
gradle --stop -> this stops the running gradle daemons but does not completely remove them, ending up with same 'could not reuse' problem.
C:\Users\<myuserdir>\.gradle\daemon\7.5.1 -> removing this directory removes all the stopped daemons completely, but this again ended up being slow as daemons are started again. On the next run we again started seeing the 'busy daemons' error.
org.gradle.daemon=true; org.gradle.parallel=true -> added these 2 lines to 'gradle.properties' files. no difference in output.
Please note that this 'gradle installdebug' is executed within different android app folders that are meant for different android apps. I'm not referring to the gradle configurations of sub-projects inside single android app. I'm also not referring to the parallel gradle tasks within a single android app.
I would highly appreciate if you can provide any input to resolve this issue as I have very limited knowledge in the gradle configuration. In a nutshell, I'm looking for a gradle configuration or parameters where all of the 'gradle installdebug' commands can run independently when executed from multiple threads. Is it possible to start 'n' number (say 10) of gradle daemons and keep it running and use it to serve 'n' commands in parallel and never stop until explicitly stopped?
Related
I am working on an Android project that uses gradle.
I have 5 tasks, say taskA, taskB, task C, taskD, taskE.
Now whenever I run taskA, it should be followed by other 4 tasks.
So, I wrote like this in my build.gradle:
taskA.finalizedBy(taskB)
taskA.finalizedBy(taskC)
taskA.finalizedBy(taskD)
taskA.finalizedBy(taskE)
But I observe that these tasks are being executed sequentially and take much time.
I have set org.gradle.parallel=true in my gradle.properties but still no luck.
Is there a way to specify these tasks to run in parallel?
Note : taskB, task C, taskD, taskE are dynamically generated by Android Gradle Plugin.
I have developed a game with LibGDX library.
I am using socket programming libraries as a module in the project.
I am planing that every process of my LibGDX game will be a client for my server.
I structured it.
But I can't run more than one game at a time to test multiplayer functionality.
When I run the game first, everything is okay, but the second time I click run anything run until the first instance is closed.
I think that's because of Gradle.
I tried to change "Build and run using IntelliJ Idea" from Gradle settings, but this time I had an exception. It cannot read my assets file.
How can I solve this problem?
enter image description here
I have solved it with a Gradle command.
./gradlew desktop:run
Same problem here. Desktop app starts but gradle build never ends and all following builds have to wait until I exit the app or stop the gradle build process.
Setting the "allow multiple instances" option in the Application run configuration did not help.
Making a gradle configuration with "desktop:run" has the same effect and "allow parallel run" did not help.
This started after the Android Studio updating to version "Arctic Fox 2020.3.1"
Starting from command line with "./gradlew desktop:run" in several terminal windows works, but is laborious.
Update with a temporary solution (until the error is fixed):
Create a JAR-Application run configuration. Build the jar in the "before launch" section with Gradle task "desktop:dist" and point to the jar in "Path to JAR".
Hints:
You can safely ignore all the "xmas" strings in the image :)
"XstartOnFirstThread" is only necessary on Mac OS.
On some recent "intellij/android studio" versions is a bug that breaks "desktop:dist" the solution is to include "duplicatesStrategy = DuplicatesStrategy.INCLUDE" in desktop/build.gradle:
task dist(type: Jar) {
manifest {
attributes 'Main-Class': project.mainClassName
}
dependsOn configurations.runtimeClasspath
duplicatesStrategy = DuplicatesStrategy.INCLUDE
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}
Enable Allow multiple instances option in Run/Debug Configuration:
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
I'm a relatively new user with Gradle, I'm working for the first time on a project (and first time with JHipster as well).
To run my application through the terminal, I execute the following command:
gradlew.bat
But at each new modification I have to kill the application ctrl + c and run it again.
I already tried using the command gradlew.bat -t build -x test (I don't want to run test each time) and gradlew.bat --continue, but both did not work.
As the bootRun task, which is the default task gradle doesn't know when to start watching, so it is not possible with gradle only. Using your ide (e.g. intellij) and the springboot devtools it is possible.
Start the application from our ide
Make changes in the code
In intellij press ctrl + F9 to compile the code and the application should restart
When you want to do it with gradle only you need two terminals and start e.g. javaCompile in continuous mode and bootRun in another terminal. The boot devtools will take care of restarting the application when it detects the newly compiled files.
gradlew compileJava -t in on terminal
gradlew bootRun in another terminal
I have a multi-project gradle build that's roughly set up like this:
RootProject
- ServiceA
- ServiceB
- ServiceC
- UI
Each of these subprojects is using the Spark framework and runs an embedded web server. It's basically a microservices setup, so they all need to be up and running for the system as a whole to work.
They each have a task defined like this:
task runApp(type: JavaExec) {
main = 'App'
classpath = sourceSets.main.runtimeClasspath
}
I know I can manually start each service either through my IDE or by opening a different terminal for each sub-project and running gradlew ServiceA:runApp, but what I'd like to do is create a runSystem task at the root level that will fire up everything to make it easy to run the whole system during development.
How can I do this with Gradle?
If you run a task on the root project, Gradle invokes the same task (if it exists) on all the subprojects. Just execute runApp from the root folder.
In your case however, your runApp task might not exit because it starts a server, so execution will not move on to the next project. You can either enable parallel execution, or modify your tasks to run your server tasks in the background (using ProcessBuilder)