Configuration closure for project.javaexec isn’t taking main as a method. Here’s some example code:
apply plugin: 'java'
def otherjar = '../hello/build/libs/hello.jar'
task runhello1(type: JavaExec, dependsOn: ":hello:build") {
classpath otherjar
main 'org.qbilt.example.Hello'
args 'hello1'
}
task runhello2 << {
javaexec {
classpath otherjar
// Why is main = required here?
Removing the = doesn't work
// with gradle 1.5.
main = 'org.qbilt.example.Hello'
args 'runnhello2'
}
}
task runhello(dependsOn: ['runhello1', 'runhello2'])
The above code works fine. Both variants of runhello run the java code with the appropriate main and args. However, if I remove the = so that I’m calling main as a method instead of invoking setMain, then I get this error for runnhello2:
Execution failed for task ':run-hello:runhello2'.
> Could not find method main() for arguments [org.qbilt.example.Hello] on project ':run-hello'.
Is there some kind of name clash in this context? Am I doing something wrong? I have observed this behavior with both gradle 1.4 and 1.5. I have not tried on any other versions.
…/hello.jar is just a jar with a main class that echoes its output.