pedrorijo91
pedrorijo91

Reputation: 7845

Short way to run gradle task on subproject

So, using gradle 5.6.1, I have a project with several nested modules/projects:

root
├── A
└── B
    └── C
        └── D

Now, if I was using maven, I could do

mvn clean install -pl :D

but in gradle it seems I need to type:

./gradle :B:C:D:assemble

which means I need to know and type the full path to the module/subproject.

Is there any shorter way, some way to pass only :D ?

ps: I'm also using gw (https://github.com/srs/gw) if relevant

Upvotes: 0

Views: 1007

Answers (2)

lance-java
lance-java

Reputation: 27976

You could achieve this via a task rule. Eg:

tasks.addRule("Pattern: -Pproject=<PROJECT> <TASK>") { String taskName ->
   def projectProp = findProperty('project')
   if (projectProp) {
      def matchingTasks = getTasksByName(taskName, true).findAll { it.project.name == projectProp }
      if (matchingTasks) { 
         task(taskName) {
            dependsOn matchingTasks
         }
      }
   }
}

Then on command line

gradle -Pproject=D assemble

Upvotes: 2

pedrorijo91
pedrorijo91

Reputation: 7845

it seems that currently there's no proper way to achieve this

Upvotes: 0

Related Questions