Is it possible to multi-thread maven sub-projects? - multithreading

I have a maven project that has sub projects which have their own child projects, configured like so:
parent pom.xml listing sub-projects as modules
sub-project 1 pom.xml listing child-projects as modules
child project 1-1 pom.xml
child project 1-2 pom.xml
sub-project 2 pom.xml listing child-projects as modules
child project 2-1 pom.xml
child project 2-2 pom.xml
child project 2-3 pom.xml
sub-project 3 pom.xml listing child-projects as modules
child project 3-1 pom.xml
Sub-project 3 depends on the output of sub-project 2, which in turn depends on the output of sub-project 1.
What I would like to accomplish is running each of the sub-projects serially, and all of the child projects in parallel. The desired order of execution would look like:
Build starts
sub-project 1 execution starts
all child projects of sub-project 1 are started in their own threads
all child projects of sub-project 1 finish execution
sub-project 1 execution ends
sub-project 2 execution starts
all child projects of sub-project 2 are started in their own threads
all child projects of sub-project 2 finish execution
sub-project 2 execution ends
sub-project 3 execution starts
all child projects of sub-project 3 are started in their own threads
all child projects of sub-project 3 finish execution
sub-project 3 execution ends
Build process completes
Using the -T command line argument for maven just starts executing all of the projects at once, like so:
Build starts
Start sub-project 1
start sub-project 2
Start sub-project 3
Start child project n...
Which fails because of dependencies between the sub-projects.
Is there any way to dictate a fine grained approach to how threads are used in maven?

I had a same use and couldn't achieve it using the -T option, as its just to tell maven to use multi-thread for building the project and if one subproject is dependent on other and it's not built yet , then obviously it will fail, instead of waiting(which IMO is correct thing to do, otherwise it could create deadlock and cause your system to hang).
Please refer https://cwiki.apache.org/confluence/display/MAVEN/Parallel+builds+in+Maven+3 for more information about the parallel builds in maven.

Related

Yarn 2 workspaces, PNP, and unit tests in child workspaces

I have a parent workspace A that has a dependency on a child workspace B. I am using PnP.
If I run yarn install in A's directory, the file .pnp.cjs is created. That's expected because I need to ensure that when packages A and B depend on a third-party package like graphql-js, only a single instance of graphql-js is loaded when A runs, or else this happens.
However, maybe I have unit tests or some yarn script I want to run directly inside project B. When I try to run the script, it complains: Usage Error: The project in B/package.json doesn't seem to have been installed - running an install there might help. OK, fine, so I run yarn install in B's directory, which creates a .pnp.cjs file in the directory. Then I try to run the tests/script again in B:
Error: Unable to locate pnpapi, the module 'B/[file]' is controlled by multiple pnpapi instances.
This is usually caused by using the global cache (enableGlobalCache: true)
Controlled by:
B/.pnp.cjs
A/.pnp.cjs
How is it possible to run unit tests or scripts in B, which requires B to have its own .pnp.cjs file, and still have dependencies controlled by A to avoid multiple instances of 3rd-party packages when A runs?

When the vue-cli-service build is completed, the process will not shut down automatically

When I used vue-cli-service to build my project, the console prompted:
DONE Build complete. The dist directory is ready to be deployed.
INFO Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html
The command I use is:
vue-cli-service build
However, the process will not automatically shut down.
Usually, I don't have to worry about this, but when I use tools like jenkins, the build process is not closed and the jenkins can't continue.
I already know the reason, because I also executed a piece of code to monitor file changes when I packaged, which made it impossible for the process to exit after packing.

How to split a gradle task execution

In my gradle project I have a task Task1 with many dependency tasks Task1Dep1, Task1Dep2, Task1Dep3... Task1DepN.
Is there a way to split my execution of Task1 such that Task1Dep1, Task1Dep2 in one execution and then run Task1Dep3 ... Task2DepN in a second execution.
The reason I want to do this is that if this is possible then it will be a solution to a problem I posted about here: How to read latest property in property file that is updated earlier in gradle execution.
I was able to solve this issue as follows.
The gradle task I wanted to run was the release task for running the Townsfolk gradle-release plugin.
Normally this would be done as:
./gradlew release
Due to various issue sI ran into with the svn support in this plugin and using it with Android I had to split the underlying sub-tasks for this plugin as follows:
./gradlew -PusesSnapshot=true -PversionModified=true initScmPlugin checkCommitNeeded checkUpdateNeeded unSnapshotVersion
./gradlew -PusesSnapshot=true -PversionModified=true initScmPlugin confirmReleaseVersion checkSnapshotDependencies build preTagCommit
svn update
./gradlew -PusesSnapshot=true -PversionModified=true initScmPlugin createReleaseTag updateVersion commitNewVersion
I found the underlying tasks using:
./gradlew tasks --all

Make a task depend on another task

I´m trying things in gradle, and I want to define a task called "jenkins" that depends on one module task called "test" and another module task called "connectedAndroidTest". I´m following the instructions on http://www.gradle.org/docs/current/userguide/more_about_tasks.html
This is my output of "./gradlew tasks"
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
[..]
Verification tasks
------------------
[..]
connectedAndroidTest - Installs and runs the tests for Build 'debug' on connected devices.
test - Runs the unit tests.
Other tasks
-----------
wrapper
So I would assume, that this:
task jenkins
jenkins.dependsOn test
jenkins.dependsOn connectedAndroidTest
would create this task, and make it depend on the other ones, so my jenkins only needs to run
./gradlew jenkins
If I have other tasks to be added to the jenkins run, I only need to change the gradle file and I don´t have to touch the jenkins.
But instead I´m getting this nasty error:
* What went wrong:
A problem occurred evaluating root project 'android-near-gradle'.
> Could not find property 'test' on root project 'android-near-gradle'.
also
task jenkins
jenkins.dependsOn unit:test
jenkins.dependsOn library:connectedAndroidTest
does lead to the same problem.
As sugested I tried this:
jenkins.dependsOn project(':unit').test
jenkins.dependsOn project(':library').connectedAndroidTest
which led to:
* What went wrong:
A problem occurred evaluating root project 'android-near-gradle'.
> Could not find property 'test' on project ':unit'.
Looking deeper into the documentation of the Gradle Objects I came up with this:
task jenkins
jenkins.dependsOn project(':unit').tasks.getByName('test')
jenkins.dependsOn project(':library').tasks.getByName('androidConnectedTest')
But this led to this error. It might be a problem, because the modules may not have been loaded yet?!
This is even more weird, because the error message is wrong
* What went wrong:
A problem occurred evaluating root project 'android-near-gradle'.
> Task with name 'test' not found in project ':unit'.
When I execute
./gradlew :unit:test
The "test" task of the module "unit" is beeing executed.
What am I doing wrong?
When declaring a task dependency like this:
task jenkins
jenkins.dependsOn test
jenkins.dependsOn connectedAndroidTest
you need to be sure that testand connectedAndroidTest tasks are already created. Since you're using the android plugin it is very likely that some tasks creations are deferred. On possible fix to that problem is to reference the tasks your jenkins task dependsOn by using the string notation. This way gradle should wire the correct tasks together no matter where in the build script (or plugins) they are declared:
task jenkins
jenkins.dependsOn "test"
jenkins.dependsOn "connectedAndroidTest"
jenkins.dependsOn ":unit:test"
jenkins.dependsOn ":unit:test"
jenkins.dependsOn "library:connectedAndroidTest"
actually works.
So referencing the tasks by string is the way to go because the other tasks are not known jet, since they are modules of the main gradle file.
Try:
jenkins.dependsOn project(':unit').test

How to run more than one test but not all the tests in GEB?

I am running gradle to run the tests from Windows command line. What I do to run a single test is:
gradlew.bat chromeTest -DchromeTest.single=test1Spec
or for all the tests:
gradlew.bat chromeTest
If I try to run only two test classes like this:
gradlew.bat chromeTest -DchromeTest=test1Spec,test2Spec--info
then gradle starts to run all the tests.
What I need: is to run only 2 or 3 Groovy classes. To be specific, neither one nor all. Any help would be really beneficial!

Resources