Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

scala - publish jar files with sbt (3rd party)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...