Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

publish jar files with sbt (3rd party)

Tags:

scala

sbt

Hello I have 5 jar files and tried to publish them to a local repository with sbt. But when I place them in unmanagedBase directory like lib/ they won't get copied with publishLocal. Is there an easy way to include them in the publishing process?

Currently maven has a similar solution here: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

like image 454
Christian Schmitt Avatar asked Oct 02 '22 17:10

Christian Schmitt


1 Answers

One option is to define a subproject for each jar that you want published. Have your main project depend on each. Give each subproject an appropriate name, version, and organization. For each subproject, put its jar somewhere not on the classpath and make the output of packageBin be that jar.

For example (sbt 0.13 build.sbt),

lazy val main = project.dependsOn(subA)

lazy val subA = project.settings(
   name := "third-party",
   organization := "org.example",
   version := "1.4",
   packageBin in Compile := baseDirectory.value / "bin" / "third-party.jar",
   // if there aren't doc/src jars use the following to
   //   avoid publishing empty jars locally
   // otherwise, define packageDoc/packageSrc like packageBin 
   publishArtifact in packageDoc := false,
   publishArtifact in packageSrc := false,
   // tell sbt to put the jar on main's classpath
   //   and not the (empty) class directory
   exportJars := true,
   // set this to not add _<scalaBinaryVersion> to the name
   crossPaths := true
)

This approach allows you to change the jar in subA/bin/third-party.jar and have it be used immediately and a subsequent publishLocal will publish it locally.

If you prefer separately publishing it locally, so that it isn't part of the project, define subA as a standalone project instead.

like image 112
Mark Harrah Avatar answered Oct 13 '22 10:10

Mark Harrah