Florian Neumann
Florian Neumann

Reputation: 5857

For what reason should i use org.gradle.api.tasks.Exec?

I'm pretty new to Gradle and have to invoke a shell command and parse it's console-output.

After doing some research how to achieve this i ended up with two ways:

  1. The Gradle-way using the task-type: Exec (org.gradle.api.tasks.Exec) with commandLine.
  2. The Groovy/Java-way using java.lang.String with execute and java.lang.Process.

The question is, why should i use the Gradle-way over the Java-way or vice versa? I couldn't find any resource pointing out the difference, yet.

Upvotes: 0

Views: 294

Answers (1)

Opal
Opal

Reputation: 84864

If what You need to do is a pretty standard task it's better to use Gradle's Exec. It's just a wrapper that also starts a command under the hood.

If what You're looking for is a better control or untypical command or maybe a dedicated handling of result it better to use execute() on String (but it's better to pass command as a List to avoid parser issues). It's more low level and needs more coding.

Upvotes: 2

Related Questions