Felix
Felix

Reputation: 88

Gradle: How to run build in user defined task?

i would like to run the build-task from the gradle war plugin inside one of my own defined tasks. I tried various things, but nothing worked.

This is how my task looks at the moment:

task deploy << {
    build.execute()
    copy {
        from '/build/libs/app.war'
        into tomcat_webapps
    }
}

When i run

gradle deploy 

the build task will not be executed. Does anyone of you know how i can do this?

Thank you!

Upvotes: 0

Views: 132

Answers (1)

dpr
dpr

Reputation: 10972

Calling tasks manually should be your very last resort. The gradle way would be to define a dependency between your task and the build task. This way gradle can determine a proper order for the tasks that need to be executed.

Setting up the dependency can be done in several ways. One way would be this:

task deploy(type: Copy) {
  dependsOn build

  from '/build/libs/app.war'
  into tomcat_webapps
}

Upvotes: 3

Related Questions