Error running gradle from gradle - can't find launcher.GradleMain


(rtayek) #1

hi, i am trying to run gradle from groovy code called from a task, so i am doing a: ‘gradle.bat’.execute(null, new File(myPath)).

this starts gradle.bat on windows.

but dirname in the batch file gets set to myPath (which is where the project that i want to build lives). so app home is bad and so is classpath which causes the error.

the line: set DIRNAME=%~dp0 in the batch file evaluates to myPath when run from groovy! the %~dp0 evaluates to the drive and path of %0 which should be where the batch file lives.

if i run gradle.bat from the command line in myPath, the %~dp0 evaluates to where the gradle.bat file lives.


(rtayek) #2

if i try to just exec gradle, he say he can’t find gradle.

if i try to exec cmd gradle, he hangs forever. adding a wait for or kill 5000 stops with no output from the exec’ed process using:

def proc = ‘cmd gradle --debug’.execute(null, new File(’…/a1’))

def b = new StringBuffer()

println ‘consuming’

proc.consumeProcessErrorStream(b)

println ‘wait or kill’

proc.waitForOrKill(5000)

println proc.text

println b.toString()


(Jesper Skov) #3

Wrong approach. You want to look at the GradleLauncher API documentation instead.


(rtayek) #4

doc says this is deprecated and recommends using connector.

but the following says:

Could not find method compile() for arguments [org.gradle.api.internal.artifac ts.dependencies.DefaultSelfResolvingDependency_Decorated@433edba9] on root proje ct ‘a’.

import org.gradle.tooling.* dependencies { compile gradleApi() } task(t) << {

ProjectConnection connection = GradleConnector.newConnector()

.forProjectDirectory(new File(’…/a1’))

.connect();

try {

connection.newBuild().forTasks(‘test’).run();

} finally {

connection.close();

} }


(Peter Niederwieser) #5

You need to apply the ‘java’ plugin to get a ‘compile’ configuration.


(rtayek) #6

of course, sorry about that. it works like a charm!


(rtayek) #7

using connector solves the problem.

thanks