Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute task in Gradle?

I have the following project structure:

  • application
    • build.gradle
  • build.gradle
  • settings.gradle

application/build.gradle:

apply plugin: 'java'

settings.gradle:

include ':application'

build.gradle:

task custom << {
  project.tasks.getByName("build").execute()
}

So I want to execute task "build" inside task "custom". But when I run "gradle custom" the result is:

:custom FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '/tmp/test/build.gradle' line: 3

* What went wrong:
Execution failed for task ':custom'.
> Task with name 'build' not found in root project 'test'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1.183 secs

How I can execute the task "build" inside task "custom" ?

like image 648
stefan.nsk Avatar asked May 21 '13 05:05

stefan.nsk


People also ask

How does Gradle task work?

Gradle ensures that all task dependencies and ordering rules are honored when executing tasks, so that the task is executed after all of its dependencies and any "must run after" tasks have been executed. Dependencies to a task are controlled using Task. dependsOn(java. lang.

What is task in build Gradle?

Each project is made up of different tasks and a task is a piece of work which a build performs. The task might be compiling some classes, storing class files into separate target folder, creating JAR, generating Javadoc, or publishing some achieves to the repositories.

How do I run a specific test in Gradle?

You can do gradle -Dtest. single=ClassUnderTestTest test if you want to test single class or use regexp like gradle -Dtest. single=ClassName*Test test you can find more examples of filtering classes for tests under this link.


1 Answers

You cannot. Task execution is declarative, not imperative. Tasks depend on each other, they do not execute each other. (Also, since you don't apply the Java (base) plugin in the root build script, the root project doesn't have a build task.)

like image 94
Peter Niederwieser Avatar answered Sep 22 '22 16:09

Peter Niederwieser