I have been trying to get this to work where I would like to evict some packages being part of the finally packaged JAR.
// Filter when packaging
excludeFilter in (Compile, unmanagedSources) ~= { _ ||
((f: File) =>
f.getPath.containsSlice("/encode/"))
}
That piece of code in my build.sbt does indeed excludes the encode package in my src directory completely, but how do I do it when I need to exclude multiple such packages? Any ideas?sbt
Related
I'd like to figure out how to excluded the Python files from the JAR file generated by the sbt package command.
The Delta lake project uses SBT version 0.13.18 and the JAR file is built with sbt package.
The directory structure is as follows:
python/
delta/
testing/
utils.py
tests/
test_sql.py
src/
main/
...scala files
build.sbt
run-tests.py
It follows the standard SBT project structure with a couple of Python files added in.
The Python files are included in the JAR file when sbt package is run and I'd like to figure out how to exclude all the Python files.
Here's what I tried adding to the build.sbt file:
mappings in (Compile, packageBin) ~= { _.filter(!_._1.getName.endsWith("py")) } per this answer
excludeFilter in Compile := "*.py" per this answer
Neither of these worked.
Haven't tested it, but I think something like this when you make a fat jar.
assemblyMergeStrategry in assembly := {
case PathList(parts # _*) if parts.last.endsWith(".py") => MergeStrategy.discard
case _ => MergeStrategy.first // or whatever you currently have for your other merges
}
How do I add additional file to classpath which is not java or scala file using SBT configuration ?
My source folder is defined like this
javaSource in Compile := baseDirectory.value / "src"
I have jawr.properties in the root of my /src folder. I'd like this file to be copied to WEB-INF/classes of my packaged app. I tried changing filter to
includeFilter in (Compile, unmanagedSources) := "*.java" || "*.scala" || "jawr.properties",
But it fails on sbt compile because it tries to compile it as java file.
I'm on SBT 0.13.6
The philosophy of SBT is to work by convention (and not by configuration) as much as possible. So the most straightforward solution, in many cases, isn't to look for the correct setting to tell SBT where your files are... But rather to figure out where SBT already expects to find them. You can check this page of the "getting started with SBT" guide for the basics.
For resource files that needs to be packaged together with compiled classes, the default directory is src/main/resources (a convention borrowed from Maven, like most of SBT's default directory structure). Similarly, files in src/test/resources are added to the classpath but only during tests.
If, for some reason, you want to use non-standard directories, you will want to have a look at this page of the documentation. For resources, the key to modify is resourceDirectory:
// resources in `resources` instead of `src/main/resources` :
resourceDirectory in Compile := baseDirectory.value / "resources"
// test resources in `test-resources` instead of `src/test/resources` :
resourceDirectory in Test := baseDirectory.value / "test-resources"
You want it be an unmanaged resource (not source)
unmanagedResourceDirectories in Compile := Seq(baseDirectory.value / "src")
includeFilter in unmanagedResources := "jawr.properties"
I want to create a standalone version of my application and was wondering how i could exclude
an unmanaged *.jar file to be packaged. It's the "mariaDB4j-2.0-SNAPSHOT.jar" file I solely
use in tests which is about 56MB huge.
I tried to put the jar file into a custom directory 'test/lib'. Unfortunately, this did not exclude mariaDB4j from packaging.
unmanagedBase <<= baseDirectory { base => base / "test/lib" }
unmanagedJars in Test <<= unmanagedBase map { base => (base ** "mariaDB4j-2.0-SNAPSHOT.jar").classpath }
Any thoughts on this?
Cheers
Oliver
I think you want to add to the testing classpath.
Two things:
You can check out what's on the classpath using show test:fullClasspath to make sure your jar is on there. Using inspect test:fullClasspath will show you what the dependencies used for testing are.
I think you can directly add your jar to the classpath via:
fullClasspath in Test += Attributed.blank(baseDirectory.value / "test/lib/mariaDB4j-2.0-SNAPSHOT")
Hope that helps!
This works, but it looks a little overstated. Changing the base directory of the unmanaged dependencies, include the file to the test's and exclude it from compile.
unmanagedBase <<= baseDirectory { base => base / "test/lib" }
unmanagedJars in Test <<= unmanagedBase map { base => (base ** "mariaDB4j-2.0-SNAPSHOT.jar").classpath }
excludeFilter in unmanagedJars in Compile := "mariaDB4j-2.0-SNAPSHOT.jar"
excludeFilter in unmanagedJars in Compile ~= { _ || "mariaDB4j-2.0-SNAPSHOT.jar" }
don't use unmanaged dependencies
if you want to keep the jar in your source repository just use a file based maven repository in your source tree with
resolvers += "Private Maven Repository" at file(".").toURI.toURL+"/repository"
then mvn install MariaDB4j locally and copy resulting stuff from maven cache to $yourproject/repository
and use the dependency like a regular managed dependency
I have a bunch of conf files in a project structure like this:
```
src / main / resources / live.conf
src / test / resources / test.conf
```
I want to excluded live.conf from the artifact that is build when I run sbt one-jar (using the one-jar plugin). I added this line which unfortunately also excludes test.conf when running sbt test:compile
excludeFilter in Runtime in unmanagedResources := "*.conf"
How can I exclude live.conf in the artifact jar but not for the tests?
This should help:
mappings in (Compile, packageBin) ~= { _.filter(!_._1.getName.endsWith(".conf")) }
packageBin is a task which produces your jar artifact and mappings denotes files wich are used for compilation and project packaging in Compile scope
I am using the SBT native packager plugin (https://github.com/sbt/sbt-native-packager) for a project composed of multiple modules.
In my SBT settings I have:
lazy val settings = packageArchetype.java_application ++ Seq(
...
// Java is required to install this application
debianPackageDependencies in Debian ++= Seq("java2-runtime"),
// Include the module JAR in the ZIP file
mappings in Universal <+= (packageBin in Compile) map { jar =>
jar -> ("lib/" + jar.getName)
}
)
The problem is that the generated ZIP, or DEB for example, do not seem to include my project's modules dependencies. There is only the final module JAR, and the libraries used in it, but not the modules that it depends on.
Do you know how could I fix that?
Found a solution to my problem:
I needed to add exportJars := true in my settings for all my internal dependencies to be embedded in the package.