Gradle : skip task does not work


I have a custom gradle plugin. In that, i have defined as below:

project.task('release', description: 'Verify project, release, and update version to next.', group: RELEASE_GROUP, type: GradleBuild) {
     startParameter = project.getGradle().startParameter.newInstance()
         tasks = [
0. (This Plugin) Initializes the corresponding SCM plugin (Git/Bazaar/Svn/Mercurial).

I have multi module project, where i want to apply the above task to some of the subprojects and not all

I triedthe below code :

beforeEvaluate { Project project ->
if (!project.hasProperty("runRoot")) {
      project.getGradle().startParameter.excludedTaskNames += "release"

But, still it executes the task. Any idea why??

Try ‘afterEvaluate’ instead of ‘beforeEvaluate’.


I tried in afterEvaluate …it is excluding for all the projects.

I will explain the scneario :

I had two projects: Root and Platform. Exclusion should happen for Platform.

At first platform got executed and exclusion was applied and it did not execute the task. Next Root got exected , but still the exclusion was there and it did not execute the task.

Should i clear the exclusion? If i used as

project.getGradle().startParameter.excludedTaskNames = ""

, it throws the below error:

* Where:
Build file 'F:\XMS\xmsWorkspace.0.00\build.gradle' line: 46
  * What went wrong:
A problem occurred configuring project ':PlatformDomain'.
> Failed to notify project evaluation listener.
   > Cannot cast object '' with class 'java.lang.String' to class 'java.lang.Ite
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.

Any idea?

‘getGradle().startParameter.excludedTaskNames’ always applies to all subprojects (after all it’s exactly the same as ‘-x’ on the command line). A good way to execute a task for a subset of projects is to only declare it for that subset of projects. Alternatively, you can set ‘someTask.enabled = false’.