gpt4 book ai didi

scala - 如何为SBT中的所有子项目设置默认依赖项?

转载 作者:行者123 更新时间:2023-12-04 03:13:30 24 4
gpt4 key购买 nike

试图了解如何设置SBT subprojects。为我的所有子项目设置默认依赖项的正确方法是什么?

我尝试了这个,但是我的子项目没有选择任何依赖项(它们下载得很好)。

import sbt._

class MyProjects(info: ProjectInfo) extends DefaultProject(info)
{
val projA = project("projA", "ProjectA")
val projB = project("projB", "ProjectB")

val akkaRepo = "Akka maven2 repo" at "http://www.scalablesolutions.se/akka/repository/"
val multiverseRepo = "Multiverse maven2 repo" at "http://multiverse.googlecode.com/svn/maven-repository/releases/"
val guiceyFruitRepo = "GuiceyFruit Maven2 repo" at "http://guiceyfruit.googlecode.com/svn/repo/releases/"
val jBossRepo = "JBoss maven2 repo" at "https://repository.jboss.org/nexus/content/groups/public/"

val junit = "junit" % "junit" % "4.5" % "test"
val scalatest = "org.scalatest" % "scalatest" % "1.2" % "test"
val akka = "se.scalablesolutions.akka" % "akka-core_2.8.0" % "0.10"
}

然后,基于 this我尝试了以下操作。它起作用了,但这不是我期望要做的。为所有子项目设置默认依赖项不是更简单吗?
import sbt._  

class MyProjects(info: ProjectInfo) extends DefaultProject(info)
{
val projA = project("projA", "ProjectA", new Proj(_))
val projB = project("projB", "ProjectB", new Proj(_))

val akkaRepo = "Akka maven2 repo" at "http://www.scalablesolutions.se/akka/repository/"
val multiversRepo = "Multiverse maven2 repo" at "http://multiverse.googlecode.com/svn/maven-repository/releases/"
val guiceyFruitRepo = "GuiceyFruit Maven2 repo" at "http://guiceyfruit.googlecode.com/svn/repo/releases/"
val jBossRepo = "JBoss maven2 repo" at "https://repository.jboss.org/nexus/content/groups/public/"

class Proj(info:ProjectInfo) extends DefaultProject(info){
val junit = "junit" % "junit" % "4.5" % "test"
val scalatest = "org.scalatest" % "scalatest" % "1.2" % "test"
val akka = "se.scalablesolutions.akka" % "akka-core_2.8.0" % "0.10"
}
}

编辑:应该指出有一个 better way来使用Akka,但是只是说明了我的观点。

最佳答案

使用继承和混合:

import sbt._

class ModularProject(info: ProjectInfo) extends DefaultProject(info){

lazy val childProject = project("projA", "ProjectA",
new DefaultProject(_)
with Repositories
with GlobalDependencies
with AkkaDependencies)

trait Repositories{
lazy val akkaRepo = "Akka maven2 repo" at
"http://www.scalablesolutions.se/akka/repository/"
lazy val multiversRepo = "Multiverse maven2 repo" at
"http://multiverse.googlecode.com/svn/maven-repository/releases/"
lazy val guiceyFruitRepo = "GuiceyFruit Maven2 repo" at
"http://guiceyfruit.googlecode.com/svn/repo/releases/"
lazy val jBossRepo = "JBoss maven2 repo" at
"https://repository.jboss.org/nexus/content/groups/public/"
}

trait GlobalDependencies{
lazy val junit = "junit" % "junit" % "4.5" % "test"
lazy val scalatest = "org.scalatest" % "scalatest" % "1.2" % "test"
}

trait AkkaDependencies{
lazy val akka = "se.scalablesolutions.akka" % "akka-core_2.8.0" % "0.10"
}

}

关于scala - 如何为SBT中的所有子项目设置默认依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4334534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com