How to run tests on dependent projects?

Hi all,

i’ve got a project (with no plugins) that just has a build target to assemble some zip archives. This project has dependencies like

    myConfig1 project(path: ':someproject', configuration: 'archives')
    myConfig2 project(path: ':anotherproject', configuration: 'archives')

where myConfig is later used in the zip task to define the input files.

Is there a way to trigger the test target in order to run all tests of ‘someproject’ and ‘anotherproject’ ? Currently it only triggers the tasks to build the dependent archives.

Have you tried ‘test.dependsOn(":someproject:test", “:anotherproject:test”)’?

Not yet (I would rather like to avoid to manually add the dependencies).

The build script is like this

task buildDistZip( type: Zip, dependsOn: [configurations.myConfig1, configurations.myConfig2]) {
artifacts {
    myArtifact buildDistZip
  task build (dependsOn: [buildDistZip]) << {

When configurations.myConfig1 is an ear archive gradle builds

someproject: compileJava->processResources->classes->jar->ear What I want to achive is that gradle would test the archive automatically (or in other words: I don’t want to use ‘untested’ dependencies. E.g. I can have unit tests failing in someproject but would still assemble it here without any warning).

I tried the approach with test.dependsOn but this just shifts the problem to other projects:

someproject and anotherproject don’t have test targets, since they are just ‘ear’ projects. They have deploy dependencies to standard java projects, which have test targets. So I would have to manually add test targets for all dependencies (I cannot believe that gradle has no automatic solution for this :wink:

someproject’s gradle looks like this:

apply plugin: 'ear'
  dependencies {
  deploy project(':somejavaprojectA')
  deploy project(':somejavaprojectB')
  ear {

Gradle has ‘buildNeeded’ (and ‘buildDependent’). If this is not what you are looking for, you can script your own solution. (‘Configuration.getTaskDependencyFromProjectDependency’ might help.)

I’ve prepared an example project to better show the project relation see []

cd into someproject: This has a dependency to earproject, which has a dependency to javaproject.

Actually the javaproject is failing (unit test), but the ear project just includes the jar, and someproject just zip’s this ear file.

I thought there would be an easy way to let the build fail whenever a dependency has failing tests (and set this to the default when building on a CI server).

What’s your goal with this? Fail sooner? Avoid consecutive errors? Or do you publish artifacts before the rest of the build has completed? And why is ‘buildNeeded’ not good enough?

The zip is a product release that we transfer to our CI serrver for download. The project is only one project of a larger multi-project build, so I have a build track that should only build this specific product release, not the whole tree. For this release I would like to run all tests that relate to this product.

buildNeeded is actually what I want, but it only applies to the java plugin. So the link breaks when using just the ear plugin for packing or just a zip task with dependencies.

‘Configuration.getTaskDependencyFromProjectDependency’ should be all you need to adapt this to your requirements/configurations. The Gradle Build Language Reference has the details.

One could also think about generalizing ‘buildNeeded’ to all configurations, so that it isn’t tied to the ‘java’ plugin anymore. Unsure about the implications.