Marin Marin - 2 months ago 19
Scala Question

Is this build.sbt ok for packaging?

I am trying to package an unmanaged jar along with some Scala code. I program using IntelliJ, and I am not sure if the package is being built correctly.

My

build.sbt
is as follows:

name := "InvokeCompiler"

version := "1.0"

scalaVersion := "2.11.8"

exportJars := true

val parserLocation = "lib/parser-0.0.1.jar"

mappings in (Compile, packageBin) ~= {

_.filter(!_._1.getName.startsWith("Main"))
}

//unmanagedJars in Compile += file(parserLocation)

mappings in (Compile, packageBin) <+= baseDirectory map { base =>

(base / parserLocation) -> "parser-0.0.1.jar"
}


I want to make a new jar file that contains the unmanaged jar and the code I wrote. This jar will be converted to a
.dll
for use it in C#. But, when doing this, IKVMC throws all sorts of warnings. When I add the
.dll
it produces the
.dll
only contains the class I wrote myself.

Answer

You don't say how you're building it, so that might be the first problem. Specifically, you should use the sbt publish-local command. To verify that the dependency is include simply unzip the JAR file and look.

If you need the resulting JAR file to be executable, then you should add this to your build.sbt:

mainClass in Compile := Some("name.of.your.main.Class")

Replace name.of.your.main.Class with your class name. You are doing something similar but potentially problematic:

mappings in (Compile, packageBin) ~= {
    _.filter(!_._1.getName.startsWith("Main"))
}

What this means is that anything that has a class name that doesn't start with Main will be filtered out. Unless you have a good reason for this, I'd get rid of it and point the package main method explicitly. What mappings does is described here.