I'm generating code using Gradle and buildSrc, now...
# community-support
g
I'm generating code using Gradle and buildSrc, now I'd like to add some tests for the generation. The generated code will be use by the
common
module, where the generation task is also registered The problem is that I'd like to use some testFixtures from one of the modules,
unit
.. is there a way to have it this way?
a
So your code-generation code is in buildSrc, and you want to write tests for it depending on some code in the repository itself? My first thought would be to move the code-generation code to a project within the repository. This would involve changing your code-generation task to use
JavaExec
(passing code paths, etc. as arguments to a
main
method) instead of calling the methods directly. I did something similar recently using roughly the following (in Groovy):
Copy code
configurations {
    codegen // creates a new configuration with this name
}
dependencies {
    codegen project(':the-codegen-project')
}
tasks.register("writeTheStuff", JavaExec) {
    classpath configurations.codegen
    mainClass.set("com.example.TheMainClass")
    args file("the/input/dir").absolutePath, file("the/output/dir").absolutePath
}
👍 1