跨平台的构建与SBT [英] Cross platform build with SBT

查看:169
本文介绍了跨平台的构建与SBT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在测试出SBT包装本地人和我期望的结果是要为每个支持的平台本机安装。显然,要做到这一点特定于平台的SBT任务将需要在该平台上运行。

I'm currently testing out SBT Native Packager and my desired result is to have a native installer for each supported platform. Obviously to do this the platform specific SBT tasks will need to run on that platform.

构建要么与Atlassian的竹子或JetBrains公司'团队市进行。

The build will either be done with Atlassian's Bamboo or JetBrains' Team City.

在理想情况下,我只会做编译和测试一次,重复使用相同的文物的包装任务。

Ideally I would only do the compilation and tests once and reuse the same artifacts for the packaging tasks.

什么是SBT解决这个好办法?

What is a good way to approach this with SBT?

我能想到的一个办法就是做任何平台上编译和测试,然后公布这些到本地存储库。然后包会以某种方式使用这些。然而,这也需要改变包装,以便它不依赖于编译任务等

One way I can think of is to do the compile and test on any platform and then publish these to a local repository. Then the package would use these somehow. However this would also require changing the packaging so that it doesn't depend on the compile task etc.

推荐答案

TL; DR版本:使用不同的SBT项目

TL;DR version: use separate sbt projects.

您可能注意到,在 JDKPackager 插件创建各种平台上的本地软件包。诀窍建设,一旦测试的主要文物是将其发布到工件的服务器,然后有一个单独的项目来创建安装程序。

As you probably noted, the JDKPackager plugin creates native packages on the various platforms. The trick to building and testing the primary artifacts once is to publish them to an artifact server, and then have a separate project for creating the installer.

如果您的项目只需要每个平台的安装程序,那么你应该需要做的就是添加的依赖,将 mainClass 键,并添加 enablePlugins(JDKPackagerPlugin)

If you your project only needs one installer per platform, then all you should need to do is add the dependency, set the mainClass key, and add enablePlugins(JDKPackagerPlugin):

enablePlugins(JDKPackagerPlugin)

name := "JDKPackagerPlugin Example"

version := "0.1.0"

organization := "com.foo.bar"

libraryDependencies += "com.foo.bar" %% "myProject" % "0.1.0"

mainClass in Compile := Some("com.foo.bar.ExampleApp")

// Optional: provide application file associations
jdkPackagerAssociations := Seq(
    FileAssociation("foobar", "application/foobar", "Foobar file type"),
    FileAssociation("barbaz", "application/barbaz", "Barbaz file type", jdkAppIcon.value)
)

如果你有,你需要每个平台多个安装程序(如命令行工具与GUI)的情景,我通常构建一个项目,有一个叫做包装与子目录独立的build.xml 文件,汇总定义每个安装配置单独的子项目:

If you have a scenario where you need multiple installers per platform (e.g. command-line tools vs. GUI), I typically structure a project to have a subdirectory called "packaging" with a stand-alone build.xml file, aggregating separate sub-projects defining each installer configuration:

// Settings common across subprojects. Could also do this with a 
// project-specific `AutoPlugin`
val baseSettings = Seq(
    libraryDependencies += "com.foo.bar" %% "myProject" % "0.1.0"
)

// The packaging aggregation project
lazy val packaging = project
   .in(file("."))
   .aggregate(a, b)

// Project with CLI configuration
lazy val a = Project(id = "my-project-cli", base = file("my-project-cli"))
  .settings(baseSettings: _*)

// Project with GUI configuration    
lazy val b = Project(id = "my-project-gui", base = file("my-project-gui"))
  .settings(baseSettings: _*)

// Create a task for invoking the sub-projects as needed
val packageSubs = taskKey[Seq[File]]("Build packages in subprojects")
(packageSubs in packaging) := {
  Seq(
    (packageBin.in(a, Universal)).value,
    (packageBin.in(b, JDKPackager)).value
  ) 
}

我觉得分手的安装配置这样有助于保持笔直的依赖,以及特定的自定义效果。

I find breaking up the installer configurations like this helps keep straight the dependencies, and effects of specific customizations.

这篇关于跨平台的构建与SBT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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