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
Related
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.
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...
i've renamed my test folder to "test". Before it was set to AndroidTest and everything works. But i have a task from my superior that the test folder must be called "test". After i renamed the folder to test in android studio the test stopped running so i went into the run configuration for the test and specified teh package name but that did not help. Here are some details on issue:
and here is the build configuration i am running for the test:
The manifest does not have anything about test in it. This is just a dummy project i made. Do i need to enter something in the manifest ?
After reading the article provided in the comments i thought i'd share how one might resolved the issue:
Android studio does not know how to respond to our test runner unless we tell it. so i made a gradle task like the following:
when you run this gradle task it will run all test cases.
To explain, here we will cleanTest (which cleans all previous tests) then we will run the test task (its like doing gradle test on command line to run test). The test dont run again if they are successful so if you give it the option of --rerun-tasks then it will return the same test task. As for the --tests * option its used to specify which tests you want to run. in my case it was everything but you can specify a class path or even down to the method level here. very useful. so its like running this on the command line: gradle test --rerun-tasks
I have a Javascript project which uses Grunt for build process, QUnit for tests, Blanket for code coverage and a custom Grunt task to convert coverage results into LCOV files, sended to Coveralls. Everything running on TravisCI.
the project : https://github.com/mistic100/jQuery-QueryBuilder
my Grunt task : https://github.com/mistic100/grunt-qunit-blanket-lcov
So what should happen is that npm test runs QUnit+Blanket tests in a PhantomJS process and in the meanwhile, coverage results are saved in .coverage-results/all.lcov.
After a successfull build, grunt coveralls sends this file to Coveralls.
And my problem is here, the task does not find the file, although when I test on my computer it does.
see the last Travis log: https://travis-ci.org/mistic100/jQuery-QueryBuilder#L389
The only thing I can think about is that the file, for some reason, is deleted once npm test is finished. Is it possible ?
edit
so this has nothing to do with Travis but with my Grunt task where I use absolute paths thinking it's relative paths (I still don't know why it doesn't append on Windows though)
The only thing I can think about is that the file, for some reason, is deleted once npm test is finished. Is it possible ?
No, lifecycle-wise the build artefacts are still present, when running after_success commands.
The gruntfile.js configures force true and defines path - no issue here.
This should work.
I would suggest to throw in some commands to check the folders and files on Travis.
- sudo ls -alh /home/travis/build/mistic100/jQuery-QueryBuilder/*
- sudo ls -alh /home/travis/build/mistic100/jQuery-QueryBuilder/.coverage-results/*
Maybe you spot a permission issue during folder and file creation.
But that's my only guess.
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