How to make javaCompile share classpath from groovyCompile in Gradle

plugins

(Rajesh Kazankodath) #1

I have a Gradle task that has both Groovy and Java source files. Both Groovy and Java source files reside within the ‘src/main/java’ sourceDirectory. Below is the sourceSet statements. The Groovy compiler compiles both the .groovy and .java files. However there are certain java files ( specified sourceSet.main.java ) that requires to be compiled with the ‘-parameters’ Java compiler option. The java files has dependencies to certain classes compiled with Groovy and hence the classpath for ‘compileJava’ requires the classes compiled with GroovyCompile.

Is there a way to modify the classpath of compileJAva to include the GroovyCompile output folder?

compileJava {
    options.fork = true
    options.compilerArgs << '-parameters' 
    options.verbose = true
    //classpath = sourceSet.main.compileClasspath
}
tasks.withType(GroovyCompile) {
    dependsOn = []
}
compileJava.dependsOn(compileGroovy)

sourceSets {
    main {
        groovy { srcDirs = ['src/main/java'] 
            excludes = ['scenarioDesigner/ScenarioDesignerUtil.java',
                'scenarioDesigner/BusinessClass.java',
                'scenarioDesigner/BusinessLayer/**']
        }
        java { srcDirs = ['src/main/java/com/myOrg/proton_ng']
            includes = ['scenarioDesigner/ScenarioDesignerUtil.java',
                        'scenarioDesigner/BusinessClass.java',
                        'scenarioDesigner/BusinessLayer/**']
        } 
    }
}