generateHollowConsumerApi chicken & egg problem 🐣
toolbear opened this issue · comments
Given a pristine (e.g. new clone or git clean
) gradle project with hollow model classes and classes that depend on the generated consumer API, the plugin cannot generate the API.
The plugin depends on a successful compile of the hollow model classes, thus the generateHollowConsumerApi
task depends on the build
task. However, the build
task attempts to compile code that requires generated consumer classes which haven't been generated yet and thus fails.
I think I have a solution for that problem. Here it is - create a JavaCompile
task, that will compile sources only under packages, that contain datamodel classes, and add this task as a dependency for generateHollowConsumerApi
.
Here is the example of task configuration in build.gradle
:
task dataModelCompile (type: JavaCompile) {
source = sourceSets.main.java.srcDirs
include 'org/example/data/**'
.... // as many lines as packagesToScan
include 'org/other/data/**'
classpath = sourceSets.main.compileClasspath
destinationDir = file('build/classes/java/main')
}
concreteCompile.options.compilerArgs = ["-sourcepath", "$projectDir/src/main/java"]
I've tested it - works like a charm!
And of course it's should be on the plugin side, it's kinda of a problem for me now. Due to lack of knowledge of some gradle api I can't pass all the arguments programmatically. I'm working on it.
And some interesting question is: if we want to support all jvm languages to write datamodel classes we have to write this kind of a tasks for Groovy, Scala, etc