Search code examples
rubybuildr

How to Locate Target Directory


Does buildr have pre-defined variables, like capistrano, for directories like 'target', 'reports', etc? If not, rather than hard-coding the location of these directories, how else can we locate/determine these paths?

The end goal is to create a task that will on-the-fly create a file and insert it into the target directory.


Solution

  • Buildr defines symbolic names for the special directories. The path_to (aka _) method accepts these symbolic names and automatically translates them into the paths for the current layout. E.g.,

    define 'foo' do
      puts _(:target, :main, :classes)    # => /some/root/foo/target/classes
      puts path_to(:source, :main, :java) # => /some/root/foo/src/main/java
    end
    

    As Antoine noted in reply to another answer, there's a list of these symbolic names in the documentation.