java - Gradle: Can I compile code that depends on its own output? -


this strange question, it's not theoretical...

  1. i'd make gradle project uses buildsrc java project inside. java project defines classes used in build process.

  2. 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:

  1. codegen (creating new java classes in buildsrc
  2. recompile buildsrc
  3. generate documentation using helpers recompiled buidsrc

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -