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 myproject/src/main/scala # Assuming there's a BUILD file with a scala_library definition named "scala" in that location
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 a single
sourcefile or a list of
sources. If you're including just a few files, you should consider specifying a sources list, e.g.
sources=['File1.scala', 'File2.scala']; if you're including, you may want to specify a
sources=globs('*.scala'). More info can be found in Use globs and rglobs to Group Files. The example further down use an
- 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:
# myproject/src/main/scala/BUILD scala_library(name='scala', sources=globs('*.scala'), dependencies=[ 'client-lib', 'analytics-lib', 'static/resources/json:config', ], )
That library can then be compiled (perhaps for debugging purposes):
$ ./pants compile myproject/src/main/scala
You can combine library targets together into a single target using a target alias. More info can be found in Create an Alias for a Target.
- Compile a Library Target
- Define a JVM Executable
- Create a Bundled zip or Other Archive
- Create an Alias for a Target