How to add sbteclipse plugin to SBT 0.10.x

2019-04-06 22:39发布

问题:

I want to view the source code of akka, and it seems using the 0.7.x version of sbt.
I transform the project configuration to the 0.10.x version. When i add sbteclipse in the libraray-dependencies and run eclipse create-src to generate eclipse project, it told that eclipse is not a command. Here is my Build.scala. The sbteclipse_2.8.1.jar is actually exists when i using library-dependencies to list the library

I was taking a silly mistake before. The plugin definition should be declared in project/plugins/build.sbt file, not as library dependency in 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:

I wasn't sure from your questions whether you were using 0.7.x or 0.10.x, but here's an answer for 0.10.x

Put the following in your ~/.sbt/plugins/build.sbt file

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))
}