How to run tests on dependent projects?


(x1000) #1

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

dependencies
 {
    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.


(Peter Niederwieser) #2

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


(x1000) #3

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).


(x1000) #4

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 {
   ...

(Peter Niederwieser) #5

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


(x1000) #6

I’ve prepared an example project to better show the project relation see [http://ge.tt/49QlCEY/v/0?c]

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).


(Peter Niederwieser) #7

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?


(x1000) #8

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.


(Peter Niederwieser) #9

‘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.