Define a Scala or Java Library Target
You need to define a new Scala or Java library target that other projects can use as a dependency.
Note: If you need to define a new Scala or Java binary target, see Define a JVM Executable
java_library target to a
BUILD file in the appropriate directory. A
java_library target will enable you to compile the library using Pants'
compile goal. Here's an example:
$ ./pants compile src/scala/com/myorg/myproject/example:hello
java_library target should specify the following:
namefor the library. This may be something like just
scalaif you have only one
scala_librarytarget in a project or something more specific like
- Either the
sourcefield with a single file or the
sourcesfield with a list of file names and globs.
- A list of
dependencies(optional). More info on dependencies can be found in Add a Dependency on Another Target.
Here's an example target definition:
# src/scala/com/myorg/myproject/example/BUILD scala_library( name='scala', sources=['*.scala'], dependencies=[ 'src/scala/com/myorg/myproject/client-lib', 'src/scala/com/myorg/myproject/analytics-lib', 'static/resources/json:config', ], )
That library can then be compiled with:
$ ./pants compile src/scala/com/myorg/myproject/example
You can combine library targets together into a single target using a target aggregate. More info can be found in Create a Target Aggregate.
- Compile a Library Target
- Define a JVM Executable
- Create a Bundled zip or Other Archive
- Create a Target Aggregate