How to split a gradle task execution - groovy

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

Related

jenkins gradle can't find groovy-all-2.5.5.jar

Have a Jenkins Pipeline that downloads a testing repo from bitbucket then does the following:
gradle build --refresh-dependencies
One of the dependencies is as follows:
compile 'org.codehaus.groovy:groovy-all:2.5.5'
We have the Pipeline running every 30min, and at least 3-4 times a day a build will fail with the following error:
Could not determine artifacts for org.codehaus.groovy:groovy-all:2.5.5
> Could not get resource '<pathToResource>/org/codehaus/groovy/groovy-all/2.5.5/grovy-all-2.5.5.jar'.
> Could not HEAD '<pathToResource>/org/codehaus/groovy/groovy-all/2.5.5/grovy-all-2.5.5.jar'.
> Read timed out
I've tried upgrading the version of groovy-all, as well as specifying the ext/type as pom. When specifying the type I get a new error as follows:
> Cannot infer Groovy class path because no Groovy Jar was found on class path:
As I said this only happens about 3-4 times a day, out of 48 builds a day, so it's very inconsistent and happens at random intervals.
We can't revert groovy-all to a previous version where the .jar exists, so is there any solution to resolve this?
You say the problem is intermittent so it sounds like you are timing out when downloading the artefact. Are you caching it locally (Artifactory, Nexus or similar)? If not, look into doing so. If you are caching locally, I'd check if something is flushing the cache

Writing a gradle task to run Junits

I am a newbee to gradle. The task at hand is to add a new gradle task that can run all the junits in the project and show a summary like which testcases passed, failed,skipped etc.
gradle version used is 4.8.1 and junit4.11
The project structure is like this:
Myproject
|_____api
| |_____src
| |_____main
| |_____test
| |____java
|_____cli
|_____src
|_____main
|_____test
|____java
I am able to run the individual tests from intelliJ.
There is a "test" method defined in the build.gradle of "cli" but I am not sure it runs. With command "gradle clean test" the build is successfull but I see no test results.
test {
include '*/cli/src/test/java/testsuites/*'
exclude '*/cli/src/test/java/com/myproject/mytool/*'
}
I have tried to add dependency and other things that I got from googling and at stackoverflow but of no use.Nothing seems to be working out.Can anyone help me to understand the basic steps and checks that I need to follow to create a gradle task for running junits? any help is appriciated.

Build - Make module/project uses wrong build type

As long as I used android studio 3.1 everything was working fine. But after the recent update to 3.2 I see following behaviour:
calling "build"/"make module" leads to execution of Executing tasks: [assemble]
calling "build"/"make project" leads to the same, assemble task is executed as well
Before the update I was able to exectue the correct assemble task (like assembleDebug<...>).
Does anyone know where I can correct this? Can I somehow check which task is bound to those menus and edit them? I have this problem with one project only...
Currently I have to manually execute the gradle task to get what I want, menu entries seem to be broken...
Setup
I am using flavours
I have selected a build variant of debug type, all my modules are set to debug as well:
apps build variant: devWithoutTestWithAccessibilityDebug
all other modules build variant: debug
Current solution
I use my own gradle tasks for my most common development build like following for now:
task runDev (type: Exec, dependsOn: 'installDevWithoutTestWithAccessibilityDebug') {
commandLine android.getAdbExe().toString(), "shell",
"monkey",
"-p", "com.my.app.debug",
"-c", "android.intent.category.LAUNCHER", "1"
}
What I tried
Clean project like following:
delete ALL *.iml files
delete .gradle and .idea folder
delete all temp files
import project again
sync project with gradle files
create app run configuration again and start it
Still I end with the same result...

Does cruisecontrol.net run the publishers section if you abort the build?

If a build is running and you go to the dashboard and abort it, does the publishers section still run?
yep it is still ran
That's the idea of publishers, to publish the result of a build :-)
build ok, build broken or build aborted.

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

Resources