使用sbt和sbt-release如何发布胖JAR(具有依赖关系的JAR)? [英] How do I publish a fat JAR (JAR with dependencies) using sbt and sbt-release?

查看:306
本文介绍了使用sbt和sbt-release如何发布胖JAR(具有依赖关系的JAR)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为我的一个子项目构建一个单一的jar,包括依赖关系,以便它可以用作 javaagent



我有一个多模块sbt项目,这个特定的模块是最低级的(它也是纯Java)。



我可以(例如, sbt-onejar sbt-proguard sbt装配)覆盖最低级别模块的打包方式?



看起来这些工具真的被设计为后发布步骤,但是我真的需要一个(替换或附加的)发布的人工制品来包含依赖关系(但仅适用于这一个模块)。



更新: Publis sbt-assembly的铰链是单个项目的说明,不容易转换为多项目。

解决方案

blockquote>

sbt-assembly的发布是单个项目的说明,不容易转换为多项目。


人们已经发布胖子JAR,使用sbt-assembly& sbt-release没有问题。以下是2011年的博客文章:发布由sbt创建的胖子 - 装配。它归结为将 addArtifact(Artifact(projectName,assembly),sbtassembly.AssemblyKeys.assembly)添加到您的 build.sbt (注意博客有点过时了 AssemblyKeys 现在是直接成为 sbtassembly 的成员)。



对于sbt 0.13及以上,我更喜欢为多项目使用 build.sbt d写如下:

  import AssemblyKeys._ 

lazy val commonSettings = Seq(
version:=0.1-SNAPSHOT,
organization = =com.example,
scalaVersion:=2.10.1


val app =(project in file(app))。
设置(commonSettings:_ *)。
设置(assemblySettings:_ *)。
设置(
artifact in(Compile,assembly)〜= {art =>
art.copy(`classifier` = Some(assembly))
}
)。
设置(addArtifact(编译,汇编),汇编).settings:_ *)

请参见定义自定义工件


addArtifact返回一系列设置(包装在SettingsDefinition中)。在完整构建配置中,使用情况如下所示:

  ... 
lazy val proj = Project(... )
.settings(addArtifact(...)。设置:_ *)
...



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 project and this particular module is the lowest level one (it's also pure Java).

Can I (e.g. with sbt-onejar, sbt-proguard or sbt assembly) override how the lowest level module is packaged?

It looks like these tools are really designed to be a post-publish step, but I really need a (replacement or additional) published artefact to include the dependencies (but only for this one module).

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

解决方案

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 : _* )
...

这篇关于使用sbt和sbt-release如何发布胖JAR(具有依赖关系的JAR)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆