user3721344
user3721344

Reputation: 221

Running a script from build directory in gradle

I want to run a script which is available in 'build/classes' directory, from 'build' directory. Because, my script reference a file whose path is relative to the build directory. Is it possible to make gradle to switch to build directory inside a particular task of type JavaExec? The snippet of build file is below.

task myrun(type:JavaExec) {     
    main = 'peep'
    args  '3'     
    classpath sourceSets.test.runtimeClasspath
    classpath sourceSets.main.runtimeClasspath
}

The peep script requires a file which is present inside build directory. Hence, i thought of switching to 'build' directory inside this task 'myrun'.

Any help?

Upvotes: 3

Views: 3574

Answers (1)

Eugen Martynov
Eugen Martynov

Reputation: 20140

According to gradle.org/docs/current/dsl/org.gradle.api.tasks.JavaExec.html there is workingDir parameter. And the default value for it is project dir.

The solution would be:

task myrun(type:JavaExec) {     
    main = 'peep'
    args  '3'     
    classpath sourceSets.test.runtimeClasspath
    classpath sourceSets.main.runtimeClasspath
    workingDir = buildDir
}

Upvotes: 4

Related Questions