Child pages
  • How to generate sources before compilation
Skip to end of metadata
Go to start of metadata

How to generate sources before compilation

Sometimes you need to generate sources files before the compilation task runs.

Here is an example that checks for changes in *.yk files and will trigger code generation and recompilation if they change.

define "generate-sources-example" do

  # whatever you use to generate your sources
  sources = FileList[_("src/main/yak/**/*.yk")]

  generate = file(_("target/generated-source") => sources) do |dir|
    mkdir_p dir.to_s # ensure directory is created
    # generate sources
    # e.g.
    # ant('generate') do |ant|
    #  ...
    # end

  compile.from generate 

Note: on Buildr 1.4.6 and earlier, you may need to add .to_s for things to work properly,

  compile.from generate.to_s

(tracked by

  • No labels

1 Comment

  1. If with this code you have error 'TypeError : can't convert Rake::FileTask into String', try to add to_s to generate so last line will be:

    compile.from generate.to_s