sbt to include unmanagedJars while publishing in build.sbt - sbt

How to include few unmanagedJars as dependecies while publishing, How to update publishingConfigaration in sbt to control dependnecy pom file.

Related

Specify jar structure in sbt assembly

When sbt-assembly builds a fat jar, it places all the dependencies in the main folder. I need to construct a jar that looks like this
--domain
domain classes
-- lib
dependency classes
is it possible to do this with sbt assembly, or any other plugin?
If you want to seperate your app jar file and your dependecy jar files, here is the most practical method i found with sbt;
Create project/plugins.sbt file if not exists and add following line:
addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.8.0")
After adding this line refresh your project.
Note: Plugin version might change in time.
When sbt refresh finishes update your build.sbt file like this:
lazy val MyApp = project.in(file("."))
.settings(artifactName := {(
sv: ScalaVersion,
module: ModuleID,
artifact: Artifact) => "MyApp.jar"
})
.settings(packSettings)
Then run:
sbt pack
Or if you're doing this for child project, run this:
sbt "project childproject" clean pack
This will nicely seperate your main jar file and your dependency jars.
Your app jar will be in target scala folder.
Your dependencies will be in target/pack/lib.
In this way you can deploy your dependencies once.
And whenever you change your app, you can just deploy your app jar file.
So in every change you don't have to deploy an uber jar file.
Also in production, you can run your app like:
java -cp "MyApp.jar:dependency_jars_folder/*" com.myapp.App

Change Classpath in SBT during test

How do I add the resourceDirectory in Java Classpath while SBT runs tests?
For now I only have sbt jar.
My need is due to a dependency (spark-cassandra-connector EmbeddedCassandra) loading a resource via ClassLoader.getSystemResourceAsStream rather than getClass().getClassLoader().getResource ...
If you want to add a new file/folder to your Java Classpth you can add the following line in your build.sbt:
(fullClasspath in Test) := (fullClasspath in Test).value ++ Seq(Attributed.blank((resourceDirectory in Test).value))
This will add the folder given by the test:resourceDirectory setting to the Classpath under the Test configuration.
Note:
The fullClasspath task provides a classpath including both the dependencies and the products of a project. For the test classpath, this includes the main and test resources and compiled classes for the project as well as all dependencies for testing.
...
fullClasspath is the concatenation of dependencyClasspath and exportedProducts
More details can be found here.

add sbt-web resources jar to classpath of sbt-native-packager

I have a multi-project build and I'm trying to add the jar with assets generated by sbt-web to the classpath of the launch script
The project I'm interested in is called website.
typing show website/web-assets:packageBin in sbt creates and shows the jar with the assets. I tried putting in (managedClasspath in website) += website/web-assets:packageBin, but that doesn't compile:
path/to/build.sbt:58: error: value / is not a member of sbt.Project
managedClasspath in website += website/web-assets:packageBin
How can I create the jar with assets when I run the stage task, and place it on the classpath of the launch script
You are mixing sbt-console commands with build.sbt commands.
The sbt-web docs give a clear example how you do it for a single project:
(managedClasspath in Runtime) += (packageBin in Assets).value
So now we do the same thing for a multi-module build. Assuming you have a build.sbt that looks like this
val root = (project in ".")
.aggregate(common, website)
val common = (project in "commons")
.settings(
libraryDependencies ++= Seq(...),
...
)
val website = (project in "commons")
.enablePlugins(JavaServerAppPackaging, SbtWeb)
.settings(
// ------ You configure it like a single module project
(managedClasspath in Runtime) += (packageBin in Assets).value
// ----------------------------------------------------
)
.dependsOn(common)
I have not directly tested this as I don't know your exact configuration. However this should give you the right direction.

sbt publish assembly jar with a pom

I am able to build one of my multi-project's jars as a single jar and then publish it How do I publish a fat JAR (JAR with dependencies) using sbt and sbt-release?
However, the associated pom.xml is not published with it.
How can I create and publish the pom.xml (and ivy file) descriptors for an sbt-assembly jar?
My project is lions-share.
Do you need to publish the contents of an existing pom.xml file, or can you let sbt generate the pom's contents for you? If the latter, consider using pomExtra:
pomExtra := (
<url>http://jsuereth.com/scala-arm</url>
<licenses>
<license>
<name>BSD-style</name>
<url>http://www.opensource.org/licenses/bsd-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>git#github.com:jsuereth/scala-arm.git</url>
<connection>scm:git:git#github.com:jsuereth/scala-arm.git</connection>
</scm>
<developers>
<developer>
<id>jsuereth</id>
<name>Josh Suereth</name>
<url>http://jsuereth.com</url>
</developer>
</developers>)
If you are making your fat jar via sbt clean assembly and want to include .pom with the jar, use sbt clean makePom assembly. This will automatically create the .pom file with the .jar file

How to embed pom descriptors in a jar

When a jar is created using Maven. The META-INF directory in the jar contains sub-directory maven/group-id/artifact-id with pom.xml and pom.properties. How to do it with SBT?
Is there an option of a plugin that does that?
You can always publish 'maven style' with sbt - This will create the pom and pom.properties correctly.
To do this, you can use:
publishMavenStyle := true
And you will probably need to add the extra information required by the pom. To do this, set pomExtra:
pomExtra :=
<licenses>
<license>
<name>Apache 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
For more information, see the docs: Publishing and the following describes in detail how to publish to a maven repo: Deploying to Sonatype.

Resources