# Gradle build with CommandLine

**URL:** <https://discuss.gradle.org/t/gradle-build-with-commandline/6580>\
**Category:** Old Forum Archive\
**Created:** [July 8, 2013, 11:23pm UTC](https://discuss.gradle.org/t/gradle-build-with-commandline/6580 "2013-07-08T23:23:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Simon](https://discuss.gradle.org/u/Simon)\
**Post date:** [July 8, 2013, 11:23pm UTC](https://discuss.gradle.org/t/gradle-build-with-commandline/6580/1 "2013-07-08T23:23:00Z")

</div>

Hello,

I am running a problem with Gradle build. Here is my build script segment

…

task svnco(type: Exec) {

commandLine ‘svn’, ‘co’, ‘[http://mysvn/products/myproduct/trunk](http://mysvn/products/myproduct/trunk)’, ‘project’

}

task myJar(type: Exec, dependsOn: svnco) {

commandLine ‘gradle’, ‘-b’, ‘project/build.gradle’, ‘install’

}

….

From Window console, in C:/mytest folder, I run

gradle myJar

The script checkout source code into project subfolder successfully. But then failed while do the gradle build:

FAILURE: Build failed with an exception.

- What went wrong:

Execution failed for task ‘:commonJar’.

> A problem occurred starting process ‘command ‘gradle’’

Then I run the script with –stacktrace option, the error shows

….

Caused by: java.io.IOException: Cannot run program “gradle” (in directory “C:\myTest”): CreateProcess error=2, The system cannot find the file specified

at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:72)

… 1 more

Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

… 2 more

I can’t tell which file it complains missing. What went wrong?

Also, how to change current working directory to a subfolder (something like ‘cd project’ )in Gradle?

Thanks, Simon

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [July 9, 2013, 6:59pm UTC](https://discuss.gradle.org/t/gradle-build-with-commandline/6580/2 "2013-07-09T18:59:00Z")

</div>

Seems it cannot find ‘gradle’. You can set the working dir for an ‘Exec’ task with the ‘workingDir’ task property.

---

<div class="post-metadata">

**Author:** ![Simon](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Simon](https://discuss.gradle.org/u/Simon)\
**Post date:** [July 9, 2013, 9:51pm UTC](https://discuss.gradle.org/t/gradle-build-with-commandline/6580/3 "2013-07-09T21:51:00Z")

</div>

Peter,

Thanks for the response.

I tried to change myJar to below, it doesn’t work.

task myJar(type: Exec, dependsOn: svnco) {

workingDir = file(‘project’)

commandLine

‘gradle’, ‘install’

}

I find a working solution as following but don’t understand why (just copied from some examples) since task svnco works fine.

task myJar(type: Exec, dependsOn: svnco) {

commandLine ‘cmd’, ‘/c’, ‘gradle’, ‘-b’, ‘project/build.gradle’, ‘install’

}

Regards, Simon

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [July 9, 2013, 10:27pm UTC](https://discuss.gradle.org/t/gradle-build-with-commandline/6580/4 "2013-07-09T22:27:00Z")

</div>

> I tried to change myJar to below, it doesn’t work.

‘file(‘project’)’ refers to a directory named ‘project’ below the project directory. Is this what you are trying to do?

> I find a working solution as following but don’t understand why

Windows batch scripts can’t be executed directly; they have to be executed with the ‘cmd’ command line interpreter (not just in Gradle but in general).

---

<div class="post-metadata">

**Author:** ![Simon](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Simon](https://discuss.gradle.org/u/Simon)\
**Post date:** [July 9, 2013, 10:39pm UTC](https://discuss.gradle.org/t/gradle-build-with-commandline/6580/5 "2013-07-09T22:39:00Z")

</div>

The code from SVN is checked out into ‘project’ which is a sub folder of where this Gradle script is running from.

I understand what you are talking about Windown batch scripts. But the task svnco doesn’t have ‘cmd’ and ‘/c’ in its commandLine setting and still works.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [July 9, 2013, 11:00pm UTC](https://discuss.gradle.org/t/gradle-build-with-commandline/6580/6 "2013-07-09T23:00:00Z")

</div>

> But the task svnco doesn’t have ‘cmd’ and ‘/c’ in its commandLine setting and still works.

My best guess is that ‘svn’ is not a batch script.
