我在SBT中有一個多項目構建配置,它由兩個不同的模塊組成,不需要彼此依賴。他們只是(碰巧)屬於同一產品。在多項目構建中爲包根項目生成沒有工件的項目SBT
項目佈局如下:
myLib
+ build.sbt
+ myProject_1
| + build.sbt
| + src
| + ...
+ myProject_2
| + build.sbt
| + src
| + ...
+ project
+ Build.scala
項目/ Build.scala包含常見的設置,如下所示:
import sbt._
import Keys._
object ApplicationBuild extends Build {
val appVersion = "1.0-SNAPSHOT"
val defaultScalacOptions = Seq(
"-unchecked", "-deprecation", "-feature", "-language:reflectiveCalls",
"-language:implicitConversions", "-language:postfixOps",
"-language:dynamics", "-language:higherKinds", "-language:existentials",
"-language:experimental.macros", "-Xmax-classfile-name", "140")
val defaultResolvers = Seq(
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
)
val defaultLibraryDependencies = Seq(
"org.specs2" %% "specs2" % "1.14" % "test",
"org.slf4j" % "slf4j-nop" % "1.7.5" % "test"
)
val defaultSettings = Defaults.defaultSettings ++ Seq(
scalacOptions ++= defaultScalacOptions,
resolvers ++= defaultResolvers,
libraryDependencies ++= defaultLibraryDependencies
)
}
根構建文件build.sbt是隻需要把所有在一起[我也試圖刪除它..但是,然後子項目不會被編譯了]:
lazy val myProject_1 = project.in(file("myProject_1"))
lazy val myProject_2 = project.in(file("myProject_2"))
最後這裏是myProject_1/build.sbt [我剛纔省略myProject_2/build.sbt,因爲它是非常相似,並且不提供對主題的任何增值]:
name := "myProject_1"
version := ApplicationBuild.appVersion
ApplicationBuild.defaultSettings
libraryDependencies ++= Seq(
"commons-codec" % "commons-codec" % "1.8"
)
項目編譯成功......但是當我發出命令sbt package
,然後在根目標目錄中生成一個空罐子:
[email protected]:~/myLib/$ ll target/scala-2.10
drwxrwxr-x 2 j3d j3d 4096 Dez 23 17:13 ./
drwxrwxr-x 5 j3d j3d 4096 Dez 23 17:13 ../
-rw-rw-r-- 1 j3d j3d 273 Dez 23 17:13 brix_2.10-0.1-SNAPSHOT.jar
我錯過了什麼嗎?我怎樣才能防止SBT產生這個空的無用的罐子?
Yessss ...剛試過SBT 0.13.1,它的工作原理;-)非常感謝。 – j3d
爲什麼我在遵循你的建議時有下列警告?警告:一個純粹的表達式在聲明中不做任何事情;你可能省略了必要的括號 (keys.'package' in(data,Compile))。value – Dzanvu
什麼是整個'build.sbt'文件?我建議提出另一個問題,所以這個問題和潛在的答案不會被埋在評論中。 –