如何将 sbteclipse 插件添加到 SBT 0.10.x
Posted
技术标签:
【中文标题】如何将 sbteclipse 插件添加到 SBT 0.10.x【英文标题】:How to add sbteclipse plugin to SBT 0.10.x 【发布时间】:2011-09-27 19:56:45 【问题描述】:想查看akka的源码,好像用的是0.7.x版本的sbt。 我将项目配置转换为 0.10.x 版本。当我在库依赖项中添加 sbteclipse 并运行 eclipse create-src 以生成 eclipse 项目时,它告诉 eclipse 不是命令。这是我的 Build.scala。当我使用库依赖项列出库时,sbteclipse_2.8.1.jar 实际上存在
我之前犯了一个愚蠢的错误。插件定义应在 project/plugins/build.sbt 文件中声明,而不是在 yourproject/build.sbt 中作为库依赖项
import sbt._
import Keys._
object Settings
import Dependencies._
import Resolvers._
val buildScalaVersion = "2.9.0-1"
val buildSettings = Defaults.defaultSettings ++ Seq(
scalaVersion := buildScalaVersion,
libraryDependencies := Depns,
resolvers := Repos)
object Resolvers
/**
* repos definition
*/
lazy val Repos = Seq(
AkkaRepo,
CodehausRepo,
GuiceyFruitRepo,
JBossRepo,
JavaNetRepo,
SonatypeSnapshotRepo,
GlassfishRepo,
ScalaToolsRelRepo,
ScalaToolsSnapshotRepo,
TypeSafeRepo)
lazy val AkkaRepo = "Akka Repository" at "http://akka.io/repository"
lazy val CodehausRepo = "Codehaus Repo" at "http://repository.codehaus.org"
lazy val GuiceyFruitRepo = "GuiceyFruit Repo" at "http://guiceyfruit.googlecode.com/svn/repo/releases/"
lazy val JBossRepo = "JBoss Repo" at "http://repository.jboss.org/nexus/content/groups/public/"
lazy val JavaNetRepo = "java.net Repo" at "http://download.java.net/maven/2"
lazy val SonatypeSnapshotRepo = "Sonatype OSS Repo" at "http://oss.sonatype.org/content/repositories/releases"
lazy val GlassfishRepo = "Glassfish Repo" at "http://download.java.net/maven/glassfish"
lazy val ScalaToolsRelRepo = "Scala Tools Releases Repo" at "http://scala-tools.org/repo-releases"
lazy val DatabinderRepo = "Databinder Repo" at "http://databinder.net/repo"
lazy val ScalaToolsSnapshotRepo = "Scala-Tools Snapshot Repo" at "http://scala-tools.org/repo-snapshots"
//type safe sbteclipse plugin repo
lazy val typesafeRepoUrl = new java.net.URL("http://repo.typesafe.com/typesafe/releases")
lazy val pattern = Patterns(false, "[organisation]/[module]/[sbtversion]/[revision]/[type]s/[module](-[classifier])-[revision].[ext]")
lazy val TypeSafeRepo = Resolver.url("Typesafe Repository", typesafeRepoUrl)(pattern)
object Dependencies
// -------------------------------------------------------------------------------------------------------------------
// Versions
// -------------------------------------------------------------------------------------------------------------------
lazy val JACKSON_VERSION = "1.7.1"
lazy val JERSEY_VERSION = "1.3"
lazy val MULTIVERSE_VERSION = "0.6.2"
lazy val SCALATEST_VERSION = "1.4.1"
lazy val JETTY_VERSION = "7.4.0.v20110414"
lazy val JAVAX_SERVLET_VERSION = "3.0"
lazy val SLF4J_VERSION = "1.6.0"
// Compile
lazy val aopalliance = "aopalliance" % "aopalliance" % "1.0" % "compile" //Public domain
lazy val aspectwerkz = "org.codehaus.aspectwerkz" % "aspectwerkz" % "2.2.3" % "compile" //ApacheV2
lazy val commons_codec = "commons-codec" % "commons-codec" % "1.4" % "compile" //ApacheV2
lazy val commons_io = "commons-io" % "commons-io" % "2.0.1" % "compile" //ApacheV2
lazy val javax_servlet_30 = "org.glassfish" % "javax.servlet" % JAVAX_SERVLET_VERSION % "provided" //CDDL v1
lazy val jetty = "org.eclipse.jetty" % "jetty-server" % JETTY_VERSION % "provided" //Eclipse license
lazy val guicey = "org.guiceyfruit" % "guice-all" % "2.0" % "compile" //ApacheV2
lazy val h2_lzf = "voldemort.store.compress" % "h2-lzf" % "1.0" % "compile" //ApacheV2
lazy val jackson = "org.codehaus.jackson" % "jackson-mapper-asl" % JACKSON_VERSION % "compile" //ApacheV2
lazy val jackson_core = "org.codehaus.jackson" % "jackson-core-asl" % JACKSON_VERSION % "compile" //ApacheV2
lazy val jersey_server = "com.sun.jersey" % "jersey-server" % JERSEY_VERSION % "provided" //CDDL v1
lazy val jsr250 = "javax.annotation" % "jsr250-api" % "1.0" % "compile" //CDDL v1
lazy val jsr311 = "javax.ws.rs" % "jsr311-api" % "1.1" % "compile" //CDDL v1
lazy val multiverse = "org.multiverse" % "multiverse-alpha" % MULTIVERSE_VERSION % "compile" //ApacheV2
lazy val multiverse_test = "org.multiverse" % "multiverse-alpha" % MULTIVERSE_VERSION % "test" //ApacheV2
lazy val netty = "org.jboss.netty" % "netty" % "3.2.4.Final" % "compile" //ApacheV2
lazy val osgi_core = "org.osgi" % "org.osgi.core" % "4.2.0" //ApacheV2
lazy val protobuf = "com.google.protobuf" % "protobuf-java" % "2.3.0" % "compile" //New BSD
lazy val sjson = "net.debasishg" % "sjson_2.9.0" % "0.11" % "compile" //ApacheV2
lazy val sjson_test = "net.debasishg" % "sjson_2.9.0" % "0.11" % "test" //ApacheV2
lazy val slf4j = "org.slf4j" % "slf4j-api" % SLF4J_VERSION
lazy val logback = "ch.qos.logback" % "logback-classic" % "0.9.28" % "runtime"
// Test
lazy val commons_coll = "commons-collections" % "commons-collections" % "3.2.1" % "test" //ApacheV2
lazy val testJetty = "org.eclipse.jetty" % "jetty-server" % JETTY_VERSION % "test" //Eclipse license
lazy val testJettyWebApp = "org.eclipse.jetty" % "jetty-webapp" % JETTY_VERSION % "test" //Eclipse license
lazy val junit = "junit" % "junit" % "4.5" % "test" //Common Public License 1.0
lazy val mockito = "org.mockito" % "mockito-all" % "1.8.1" % "test" //MIT
lazy val scalatest = "org.scalatest" % "scalatest_2.9.0" % SCALATEST_VERSION % "test" //ApacheV2
lazy val sbteclipse = "com.typesafe.sbteclipse" % "sbteclipse_2.8.1" % "1.1" extra ("sbtversion" -> "0.10.0")
val Depns = Seq(
aopalliance,
aspectwerkz,
commons_codec,
commons_io,
javax_servlet_30,
jetty,
guicey,
h2_lzf,
jackson,
jackson_core,
jersey_server,
jsr250,
jsr311,
multiverse,
multiverse_test,
netty,
osgi_core,
protobuf,
sjson,
sjson_test,
slf4j,
logback,
commons_coll,
testJetty,
testJettyWebApp,
junit,
mockito,
scalatest,
sbteclipse)
object AkkaBuild extends Build
import Settings._
import Resolvers._
lazy val akka = Project("akka", file("."), settings = buildSettings)
.aggregate(
akka_actor,
akka_testkit,
akka_actor_tests,
akka_stm, akka_typed_actor,
akka_remote, akka_http,
akka_samples, akka_slf4j,
akka_tutorials)
lazy val akka_actor = Project("akka-actor", file("akka-actor"), settings = buildSettings)
lazy val akka_testkit = Project("akka-testkit", file("akka-testkit"), settings = buildSettings) dependsOn (akka_actor)
lazy val akka_actor_tests = Project("akka-actor-tests", file("akka-actor-tests"), settings = buildSettings) dependsOn (akka_testkit)
lazy val akka_stm = Project("akka-stm", file("akka-stm"), settings = buildSettings) dependsOn (akka_actor)
lazy val akka_typed_actor = Project("akka-typed-actor", file("akka-typed-actor"), settings = buildSettings) dependsOn (akka_stm, akka_actor_tests)
lazy val akka_remote = Project("akka-remote", file("akka-remote"), settings = buildSettings) dependsOn (akka_typed_actor)
lazy val akka_http = Project("akka-http", file("akka-http"), settings = buildSettings) dependsOn (akka_actor)
lazy val akka_samples = Project("akka-samples", file("akka-samples"), settings = buildSettings)
lazy val akka_slf4j = Project("akka-slf4j", file("akka-slf4j"), settings = buildSettings) dependsOn (akka_actor)
lazy val akka_tutorials = Project("akka-tutorials", file("akka-tutorials"), settings = buildSettings) dependsOn (akka_actor)
【问题讨论】:
【参考方案1】:我不确定您使用的是 0.7.x 还是 0.10.x,但这里是 0.10.x 的答案
将以下内容放入您的 ~/.sbt/plugins/build.sbt
文件中
resolvers +=
val typesafeRepoUrl = new java.net.URL("http://repo.typesafe.com/typesafe/releases")
val pattern = Patterns(false, "[organisation]/[module]/[sbtversion]/[revision]/[type]s/[module](-[classifier])-[revision].[ext]")
Resolver.url("Typesafe Repository", typesafeRepoUrl)(pattern)
libraryDependencies <<= (libraryDependencies, sbtVersion) (deps, version) =>
deps :+ ("com.typesafe.sbteclipse" %% "sbteclipse" % "1.1" extra("sbtversion" -> version))
【讨论】:
我实际上使用的是 0.10.x,在 sbteclipse git 存储库的自述文件中,我发现:首先你必须“安装”插件。从 SBT 0.10 (0.9) 开始,这就像在项目中添加对 sbteclipse 的库依赖一样简单。甚至更好:在 ~/.sbt/plugins 目录中创建一个全局插件项目(只是一个 build.sbt 文件) 表示在项目的Build.scala或者全局的Build.scala中都OK! 是的,您的解决方案有效。但是,为什么我的解决方案不起作用。我真的很困惑。 当然可以,但是你知道为什么我不能在我的项目的 Build.scala 中添加插件吗?欢迎任何答案以上是关于如何将 sbteclipse 插件添加到 SBT 0.10.x的主要内容,如果未能解决你的问题,请参考以下文章
sbt eclipse 错误评估任务 scalaoptions 错误