It would be nice to finish this one day, but it is just a sketch so far. Additionally, maybe people should use maven instead of ant....
Ant (LINK) is a tool for managing the conversion of source code into built programs that is particularly popular among those who work with Java. This file describes how to use Ant with Scala code.
Scala Bazaars allows distributing both complete applications and individual libraries. It helps you obtain and manage packages from world-wide shared repositories, from others in your organization, and from code on your own machine. You may as well use it to handle dependencies between portions of your own project.
The general approach, then, is that when you build something and are ready to use it, you should install it in your own sbaz directory for use by other tools. If you want others in your organization or around the world to also use the package, then post your package on an appropriate sbaz index server. If you are compiling something that has a dependency, find that dependency in your sbaz directory. This way, components can be developed independently and then inter-component dependencies can be managed by sbaz.
To locate your sbaz directory, your build.xml
file
should start with a definition of the scala.home
property:
It is also convenient to define a current version number for the code being built:
Finally, it is important to include the standard Ant header supplied along with the Scala compiler.
Documentation on these tasks can be found at: (LINK)
There is no one right way to lay out a directory tree. A common layout for Scala programmers, assumed for the rest of this article, goes like this:
build
- All built files go into this directory.
It is especially important with ant that all built files go into
a separate directory, because Ant does not otherwise make it easy
to implement a "clean" target.
src
- The Scala source code. You should arrange it
so that the subdirectory structure corresponds as closely as
possible to the package structure of your code, because various
Scala tools use the directory layout as a heuristic. For example,
a class named sbaz.keys.Key
should be located at
src/sbaz/keys/Key.scala
if possible. If you are
compiling multiple jars, then src
should have
a subdirectory for each jar you are compiling.
tests
- A JUnit test suite for your code. This is
arranged just like src
, but is probably not included
in the distributed program.
docs
- Any documentation you have for your project.
examples
- Any code you have that is related to the
project but is not part of the main jar(s) you are building. It
is good to keep such code in the directory tree of the project it
is part of, but you also do not normally want to put it in
src
.
The following are some targets it makes sense to define in your
build.xml
:
build
- builds Scala code into jars
dist
- builds sbaz packages
install
- installs sbaz packages
clean
- deletes all built files
toolScripts
- build scripts
to run your code from a command line
tests
- builds your SUnit tests into a jar
api
- runs scaladoc across sources to produce
API documentation
These targets are described one by one below with an example given of each.