2016-06-20 66 views
2

我正在將幾個大型scala項目合併爲一個。目前他們使用剪切和粘貼(不是非常多的代碼)來共享代碼,而我正在使它有一個通用的實用程序jar。這些項目中的大多數都部署在亞馬遜雲上,並使用sbt-native-packager對其進行打包如何在多個項目中使用sbt-native-packager

我的問題是我不知道如何配置多個項目的sbt本地管理器。我也不是很熟悉它,在所有最初的工作完成後進入了這個項目。

我已經將問題減少到了我能得到的最小問題。有一個在https://github.com/stave-escura/multiprojectissue.git一個git回購這表明了問題

在項目/ plugins.sbt的重要線

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.6") 
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.0") 

的build.sbt太長,擺在這裏,但粗糙的形狀它是

import com.typesafe.sbt.SbtNativePackager 
import com.typesafe.sbt.packager.archetypes.JavaServerAppPackaging 

enablePlugins(SbtNativePackager) 

enablePlugins(JavaServerAppPackaging) 

lazy val commonSettings = Seq(
    ... 
    scalaVersion := "2.11.8", 
    assemblyJarName in assembly := s"${name.value}.jar", 
    assemblyMergeStrategy in assembly := { 
    case "BUILD" => MergeStrategy.discard 
    case other => MergeStrategy.defaultMergeStrategy(other) 
    } 
) 

lazy val project1Settings = commonSettings ++ Seq(
    rpmVendor := "someOrganisation", 
    packageDescription in Rpm := "Some description1", 
    rpmLicense := Some("Copyright 2016 someOrganisation. All rights reserved."), 
    rpmRequirements := Seq(
    "java-1.8.0-openjdk" 
), 
    version in Rpm := "1", 
    rpmRelease := version.value, 
    rpmDaemonLogFile := s"${name.value}.log", 
    daemonUser in Linux := "someUserName", 
    daemonGroup in Linux := (daemonUser in Linux).value, 
    rpmPost := Some(
    """|chkconfig --add someService1 
     |chkconfig someService1 on 
    """.stripMargin), 
    linuxPackageMappings ++= Seq() // <--- line 53 
) 


lazy val project2Settings = commonSettings ++ Seq(
    identical to project 1 settings except 
    packageDescription in Rpm := "Some description2", 
    rpmPost := Some(
    """|chkconfig --add someService2 
     |chkconfig someService2 on 
    """.stripMargin), 
    linuxPackageMappings ++= Seq() // <--- line 72 
) 

lazy val project1 = (project in file("components/service1")).settings(project1Settings: _*) 

lazy val project2 = (project in file("components/service2")).settings(project2Settings: _*) 

在真正的項目中linuxPackageMappings相當複雜,是我的問題。他們在項目之間有所不同。當我build.sbt加載到SBT我得到錯誤

References to undefined settings: 

    project2/*:linuxPackageMappings from project2/*:linuxPackageMappings (~/git/multiprojectissue/build.sbt:72) 

    project1/*:linuxPackageMappings from project1/*:linuxPackageMappings (~/git/multiprojectissue/build.sbt:53) 

    at sbt.Init$class.Uninitialized(Settings.scala:265) 
    ... 
    at xsbt.boot.Boot.main(Boot.scala) 
[error] References to undefined settings: 
[error] 
[error] project2/*:linuxPackageMappings from project2/*:linuxPackageMappings (/Users/ricep02/git/multiprojectissue/build.sbt:72) 
[error] 
[error] project1/*:linuxPackageMappings from project1/*:linuxPackageMappings (/Users/ricep02/git/multiprojectissue/build.sbt:53) 

線53和72被標記在build.sbt代碼段I中包括在內。

事情我不知道 我沒有足夠的技術在這個知道爲什麼該項目已SBT組裝和SBT-包管理器。我的評論SBT組裝出plugins.sbt的,仍然可以得到這個問題,所以我在此刻不認爲這是促成

事情我已經試過 我試圖把分項目設置到與實際組件相關的build.sbt文件中。我遇到同樣的問題。 我也很好地看了一個例子項目,比如https://github.com/muuki88/sbt-native-packager-examples/tree/master/multi-module-build,並且仔細閱讀了http://www.scala-sbt.org/sbt-native-packager/的文檔,雖然我對它沒有'經驗':只是在'閱讀文檔'級別。我也看了看問題,比如How to setup sbt-native-packager in a single module project with multiple mainsHow to create a basic project setup using sbt-native-packager

的工作 離開packageMappings在build.sbt的「主體」不會導致「SBT負載問題」的東西,但我不不知道它是否會真正建立包裝!

軟件堆棧

  • 操作系統:Mac系統
  • 的Java:1.8.0_74-B02
  • 斯卡拉:2.11.8
  • SBT:0.13.8
  • SBT-本地-packager 1.0.6

回答

0

它看起來像0需要在其設置中爲project1project2啓用。

嘗試通過增加enablePlugins(SbtNativePackager)修改設置:

lazy val project1Settings = commonSettings ++ Seq(
    rpmVendor := "someOrganisation", 
    packageDescription in Rpm := "Some description1", 
    rpmLicense := Some("Copyright 2016 someOrganisation. All rights reserved."), 
    rpmRequirements := Seq(
     "java-1.8.0-openjdk" 
    ), 
    version in Rpm := "1", 
    rpmRelease := version.value, 
    rpmDaemonLogFile := s"${name.value}.log", 
    daemonUser in Linux := "someUserName", 
    daemonGroup in Linux := (daemonUser in Linux).value, 
    rpmPost := Some(
     """|chkconfig --add someService1 
      |chkconfig someService1 on 
     """.stripMargin), 
    enablePlugins(SbtNativePackager), 
    linuxPackageMappings ++= Seq() // <--- line 53 
) 

,也同樣項目2

我建議「在行動SBT」,以幫助您開始得到一本書像「簡單的「構建工具。

+0

'enablePlugins(SbtNativePackager)'看起來是在一個有趣的地方。你還記得如果你有上面的編譯?它是'DslEntry'類型,而不是'Def.SettingsDefinition'。 sbt 0.13.15,sbt-native-packager 1.2.0 – akauppi

相關問題