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
  end

  compile.from generate 
end

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 https://issues.apache.org/jira/browse/BUILDR-609)

  • 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