How do I publish a fat JAR (JAR with dependencies) using sbt and sbt-release?

后端 未结 1 1848
醉梦人生
醉梦人生 2020-12-29 09:00

I need to build a single jar, including dependencies, for one of my sub-projects so that it can be used as a javaagent.

I have a multi-module sbt projec

相关标签:
1条回答
  • 2020-12-29 09:27

    Publishing for sbt-assembly are instructions for a single project, and doesn't easily translate into multi-project.

    People have been publishing fat JAR using sbt-assembly & sbt-release without issues. Here's a blog article from 2011: Publishing fat jar created by sbt-assembly. It boils down to adding addArtifact(Artifact(projectName, "assembly"), sbtassembly.AssemblyKeys.assembly) to your build.sbt (note that the blog is a little out of date AssemblyKeys is now a member of sbtassembly directly).

    For sbt 0.13 and above, I prefer to use build.sbt for multi-projects too, so I'd write it like:

    import AssemblyKeys._
    
    lazy val commonSettings = Seq(
      version := "0.1-SNAPSHOT",
      organization := "com.example",
      scalaVersion := "2.10.1"
    )
    
    val app = (project in file("app")).
      settings(commonSettings: _*).
      settings(assemblySettings: _*).
      settings(
        artifact in (Compile, assembly) ~= { art =>
          art.copy(`classifier` = Some("assembly"))
        }
      ).
      settings(addArtifact(artifact in (Compile, assembly), assembly).settings: _*)
    

    See Defining custom artifacts:

    addArtifact returns a sequence of settings (wrapped in a SettingsDefinition). In a full build configuration, usage looks like:

    ...
    lazy val proj = Project(...)
      .settings( addArtifact(...).settings : _* )
    ...
    
    0 讨论(0)
提交回复
热议问题