Gradle build with CommandLine

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’, ‘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

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

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

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).

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.

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.