Bohdan Nesteruk
Bohdan Nesteruk

Reputation: 914

Gradle: exclude triggering sub-project task when root task is called

I have the following project-structure:

Root project 'base'
+--- Project ':server'
+--- Project ':testManager'

Each module has its own artifactoryPublish task.

How can I exclude execution of artifactoryPublish of testManager module when I run the root task in the base root dir?

> ./gradlew artifactoryPublish - this should not run the testManager:artifactoryPublish.

But I need to be able to run this task separately for one testmanager module:

> ./gradlewtestManager:artifactoryPublish` - this should start the task in specified module.

I tried to add the following to settings.gradle:

startParameter.excludedTaskNames << ':testManager:artifactoryPublish'

But in this case the task is skipped always even if I run it with the module name.

Or maybe there is a way to check if artifactoryPublish was called only for testManager, otherwise set artifactoryPublish.skip flag?

Thanks in advance.

Upvotes: 1

Views: 772

Answers (3)

Denys Zotov
Denys Zotov

Reputation: 21

You can just add to build.gradle of testManager module next script

artifactoryPublish.onlyIf { false }

Upvotes: 0

Bohdan Nesteruk
Bohdan Nesteruk

Reputation: 914

The solution that suits my case is to add the following to the testManager build.gradle:

artifactoryPublish.onlyIf { 
    ext.has("publishTestFiles") 
}

This allows using additional flags only if the launch of this module's task is required.

Upvotes: 0

Frank Neblung
Frank Neblung

Reputation: 3175

You can exclude tasks from running with -x switch

$> gradle --dry-run artifactoryPublish
:artifactoryPublish SKIPPED
:server:artifactoryPublish SKIPPED
:testManager:artifactoryPublish SKIPPED

$> gradle --dry-run artifactoryPublish -x :testManager:artifactoryPublish
:artifactoryPublish SKIPPED
:server:artifactoryPublish SKIPPED

Upvotes: 1

Related Questions