java - Gradle: Can I compile code that depends on its own output? -
this strange question, it's not theoretical...
i'd make gradle project uses
buildsrc
java project inside. java project defines classes used in build process.the nasty trick is, gradle project produces bunch of outputs, including modified classes belong java project of
buildsrc
itself.
is there way express gradle?
the solution have in mind right is: run whole build script twice in row. there way avoid that? example, generating modified code buildsrc
, re-compiling buildsrc
, generating additional outputs of main gradle project?
okay, building on michael easter's awesome example, can have main-level build call gradlebuild
on 1 of own tasks:
task generatenewcode() << { println("tracer top build") // buildtool java class defined in `buildsrc` // ... , has cyclic dependency on own // output (eek -- that's i'm dealing with!) buildtool.generatenewcode(); } task generatedocs(type: gradlebuild) { buildfile='build.gradle' tasks = ['generatedocs_real'] } task generatedocs_real << { buildtool.outputdocumentation(); } generatedocs.dependson generatenewcode
then can invoke gradle generatedocs
do:
- codegen (creating new java classes in
buildsrc
- recompile
buildsrc
- generate documentation using helpers recompiled
buidsrc
Comments
Post a Comment