1
votes

I have a JavaExec task which runs a Java class to generate files. The source code generator needs to search CLASSPATH to find certain classes it uses to determine what to generate. It needs the current project's classes to be in CLASSPATH.

I have this task:

task showClasspath(type: JavaExec) {
    main = "com.my.codegen.Main"
    classpath = sourceSets.main.runtimeClasspath
    classpath += project(":CodeGen").sourceSets.main.runtimeClasspath
    args "generate",
}

When I run this task I get "Circular dependency between the following tasks:". So obviously I'm referring classpath back to itself.

If I use this task then the project classes are not in CLASSPATH:

task showClasspath(type: JavaExec) {
    main = "com.my.codegen.Main"
    classpath += project(":CodeGen").sourceSets.main.runtimeClasspath
    args "generate",
}

I've been going around in circles for hours on this and could really use some help.

Thanks in advance!

1

1 Answers

1
votes

I found the problem. I was being stupid and had forgotten I had this:

compileJava.dependsOn generateJava

The generatejava referred back to my code gen task so it was indeed a loop of my own creation.