Exclude task from other subproject

Hi,

I have multi-projects build. There are java projects and packaging project. Packaging project have task which depends on java project build task:

task preparePackage(dependsOn: ‘:java:A:build’)

I would like to exclude test run from java project when I’m calling task preparePackage from command line. But if I call “gradle preparePackage -x test” then I get: Task ‘test’ not found in project ‘:package’.

Is there any way to easy skip test run in such configuration?

Thanks,
Michał

What does the ‘preparePackage’ task actually depend on? What I mean is, what output is required, the JAR? If so then you could potentially use a project dependency to model this rather than depending on the ‘build’ task.

‘preparePackage’ task requires only jars to create deployment archive for my application, so I could just use assemble task from java projects. However I wanted to use this task as final task in our CI/productions builds. In such case this task should also run “test” task on all depended java projects. It should be also possible to prepare such package quickly, without running java tests, for dev tests. “-x” switch seemed to be best solution for that, but it looks like it doesn’t work as I expected and I would like to understand what I missing here.

When I call “build” task on java project gradle will create task graph and with “-x test” switch it will remove all branches of this graph with “test” task. Why this doesn’t work if tasks belongs to different projects? I’ve expected that similar task graph will be created, but with “preparePackage” as root task and “-x” switch will still exclude “test” tasks from such graph.

Thanks,
Michal

You should really be using project dependencies for this rather than depending on a task from another project.

In that case you CI build should do something like gradle perparePackage test.