Reputation: 309
I need to execute a java class which has a main method in it before compiling the code. This is what I have tried so far:
task runSimple(type: JavaExec) {
main = 'jjrom.ObjectGen'
classpath = sourceSets.main.runtimeClasspath
File prop1 = file(propFilePath)
args '-sqlserver', '-force', prop1.path
println "I'm done executing."
}
compileJava {
dependsOn runSimple
}
When I execute this script with the command "gradle compileJava" , I get this error message:
I'm done executing.
FAILURE: Build failed with an exception.
What went wrong: Circular dependency between the following task: :classes --- :compileJava --- :runSimple --- :classes (*)
Upvotes: 5
Views: 13548
Reputation: 1285
If you need to run JavaExec
only with dependecies
classpath, just change classpath
variable to something like:
classpath = configurations.compile
Or if you are interested in very specific classpath, you could add custom configuration like this:
configurations {
customClasspath
}
dependencies {
customClasspath files('path/to/your.jar')
}
task runSimple(type: JavaExec) {
main = 'jjrom.ObjectGen'
classpath = configurations.customClasspath
File prop1 = file(propFilePath)
args '-sqlserver', '-force', prop1.path
println "I'm done executing."
}
compileJava {
dependsOn runSimple
}
Upvotes: 0
Reputation: 123960
If you need to execute this class before compiling the code, you can't give it classpath = sourceSets.main.runtimeClasspath
. The latter includes the compiled code, and so Gradle automatically infers runSimple.dependsOn compileJava
, which together with your compileJava.dependsOn runSimple
gives a cyclic task dependency. (To be precise, Gradle infers runSimple.dependsOn classes
, which in turn depends on compileJava
.)
Upvotes: 3