I am trying to setup SBT to compile an existing project which does not use the maven directory structure. I am using the full configuration and have set my javaSource & resourceDirectory settings as follows:
def settings = Defaults.defaultSettings ++ Seq(
resourceDirectory in Compile <<= baseDirectory( _ / "java" ),
javaSource in Compile <<= baseDirectory( _ / "java" )
)
Now I want to be able to filter the resources we include in the jar artifact, as we currently do with ant, plus exclude .java files as our resources are mixed in with source code. For example:
<fileset dir="java" includes="**/*.txt, **/*.csv" excludes="**/*.java" />
Is there any way to do this?
Use
defaultExcludesscoped for theunmanagedResourcestask and optionally the configuration. For example, this setting excludes .java files from the main resources:in Compilerestricts this setting to only apply to main resources. By usingin Testinstead, it would apply only to test resources. By omitting a configuration (that is, noin Compileorin Test), the setting would apply to both main and test resources.in unmanagedResourcesapplies these excludes for resources only. To apply excludes to sources, for example, the scope would bein unmanagedSources. The reason for the unmanaged part is to emphasize that these apply to unmanaged (or manually edited) sources only.The
defaultExcludeskey has type sbt.FileFilter, so the setting value must be of this type. In the example above,"*.java"is implicitly converted to a FileFilter.*is interpreted as a wildcard and so the filter accepts files with a name that ends in ‘.java’. To combine filters, you use||and&&. For example, if .scala files needed to be excluded as well, the argument to:=would be:In the original Ant fileset, the include and exclude filters select mutually exclusive sets of files, so only one is necessary.
It is also possible to directly build the
Seq[File]forunmanagedResources. For example:The
**method selects all descendents that match theFileFilterargument. You can verify that the files are selected as you expect by runningshow unmanaged-resources.