sbt 笔记
所属分类 sbt
浏览量 600
project/build.properties 指定sbt的版本
When a val is declared as lazy, its initialization is deferred until it is accessed for the first time.
三种类型的key
SettingKey[T]
a key for a value computed once (the value is computed when loading the subproject, and kept around)
TaskKey[T]
a key for a value, called a task, that has to be recomputed each time, potentially with side effects.
InputKey[T]
a key for a task that has command line arguments as input
内置 key
自定义 key
定义 Task 和 Settings
TaskKey[T] 用来定义task ,task是一些操作,比如 compile package 等
settints可以直接在build.sbt中定义,不用写在.settings()中,这种定义称为bare style
bare 光秃秃的 裸露的 裸体的
ThisBuild / useCoursier := false
lazy val root = (project in file("."))
.enablePlugins(plugin1, plugin2, ...)
.disablePlugins(plugin1 , plugin1 ,...)
.settings(
slick := slick.value,
Compile / run := {
(xxxProject / Test / test).value
(Compile / run).evaluated
},
excludeDependencies ++= Seq()
)
.aggregate(project1, project2, ...)
.dependsOn(project1, project2, ...)
lazy val subProject1 = project in file("subProjectRoot/subProject1")
lazy val subProject2 = project in file("subProjectRoot/subProject2")
subproject 之间 可以独立 ,可以建立依赖
aggregate and classpath
Aggregation means that running a task on the aggregate project will also run it on the aggregated projects
lazy val root = (project in file("."))
.aggregate(core, util)
lazy val util = project in file("util")
lazy val core = (project in file("core") ).dependsOn(util)
Library dependencies
非托管库 unmanaged dependencies 放在lib/路径下的jar包
托管库 managed dependencies 在构建定义中(build definition)配置,由sbt自动下载
unmanagedBase := baseDirectory.value / "custom_lib"
libraryDependencies ++= Seq(
"org.apache.spark" % "spark-core_2.10" % "1.6.0" % "provided",
"org.apache.hadoop" % "hadoop-client" % "2.6.4" % "provided"
)
// 仓库
resolvers ++= Seq(
"Admonitor Repository" at "http://maven.mzsvn.com/repository/xxx",
"Local Maven Repository" at "file:///home/xxx/.m2/repository"
)
上一篇
下一篇
Maven 打包 定制 manifest
pf4j 实例
Jooq 简介及实例
scala sbt 项目增加子项目
老子骑青牛出函谷关
创业公司CTO岗位职责