2016-09-15 74 views
0

多個zip工件我有以下的項目結構:生產從一個SBT模塊

my-project/ 
    build.sbt 
    ... 
    app/ 
    ... 
    config/ 
    dev/ 
     file1.properties 
     file2.properties 
    test/ 
     file1.properties 
     file2.properties 
    prod/ 
     file1.properties 
     file2.properties 

該模塊的應用程序包含一些階的源代碼,並且產生一個普通的jar文件。

問題出在配置模塊。我需要做的是在build.sbt中創建一些配置,它將從配置中獲取每個文件夾並將其內容放入單獨的zip文件中。

結果應該如下:

my-project-config-dev-1.1.zip ~> 
    file1.properties 
    file2.properties 
my-project-config-uat-1.1.zip ~> 
    file1.properties 
    file2.properties 
my-project-config-prod-1.1.zip ~> 
    file1.properties 
    file2.properties 

1.1是該項目的任意版本。

配置應該以這樣的方式工作,當我添加新的環境和新的配置文件時,將生成更多的zip文件。在另一個任務中,所有這些zip文件都應該發佈到Nexus。

有什麼建議嗎?

回答

0

我設法通過創建一個模塊config然後爲每個環境單獨的子模塊來解決問題,所以項目結構看起來完全如所述。現在全部來到build.sbt的適當配置。

下面是我做了什麼來達到我想要的一般想法。

lazy val config = (project in file("config")). 
    enablePlugins(UniversalPlugin). 
    settings(
    name := "my-project", 
    version := "1.1", 
    publish in Universal := { },  // disable publishing of config module 
    publishLocal in Universal := { } 
). 
    aggregate(configDev, configUat, configProd) 

lazy val environment = settingKey[String]("Target environment") 

lazy val commonSettings = makeDeploymentSettings(Universal, packageBin in Universal, "zip") ++ Seq( // set package format 
    name := "my-project-config", 
    version := "1.1", 
    environment := baseDirectory.value.getName,            // set 'environment' variable based on a configuration folder name 
    topLevelDirectory := None,                // set top level directory for each package 
    packageName in Universal := s"my-project-config-${environment.value}-${version.value}", // set package name (example: my-project-config-dev-1.1) 
    mappings in Universal ++= contentOf(baseDirectory.value).filterNot { case (_, path) => // do not include target folder 
    path contains "target" 
    } 
) 

lazy val configDev = (project in file("config/dev")).enablePlugins(UniversalPlugin).settings(commonSettings: _*) 
lazy val configUat = (project in file("config/uat")).enablePlugins(UniversalPlugin).settings(commonSettings: _*) 
lazy val configProd = (project in file("config/prod")).enablePlugins(UniversalPlugin).settings(commonSettings: _*) 

UniversalPlugin是高度可配置的,雖然不是所有的配置選項可能會在第一次明確。我建議閱讀它的文檔並查看源代碼。

要實際打包僞像以下命令具有發出:

sbt config/universal:packageBin 

出版:

sbt config/universal:publish 

如上述添加新的環境中可以看出是很容易的 - 只有一個新文件夾和一個線需要添加build.sbt

相關問題