【问题标题】:How do you do develop an SBT project, itself?您如何开发 SBT 项目本身?
【发布时间】:2013-04-08 06:42:02
【问题描述】:

背景:我有一个 Play 2.0 项目,我正在尝试添加一些东西来使用我的一些类 (Java) 的 jar 中的方面进行 aspectj 编织。 (sbt-aspectj 似乎没有这样做,或者我看不出怎么做)。所以我需要添加一个自定义任务,并让它依赖于编译。我已经弄清楚了依赖部分。但是,因为我不知道自己在做什么,所以我想使用 IDE 开发它(我使用的是 Scala-IDE)。由于 sbt 项目(以及因此 Play 项目)是递归定义的,我认为我可以:

  1. 将eclipse插件添加到myplay/project/project/plugins.sbt
  2. 将 sbt 主 jar(和 aspectj jar)添加到 myplay/project/project/build.sbt:

    libraryDependencies ++= Seq( "org.scala-sbt" % "main" % "0.12.2", “aspectj”%“aspectj工具”%“1.0.6” )

  3. 放入 myplay/项目

  4. 运行 sbt,运行 eclipse 任务,然后将项目作为单独的项目导入 eclipse。

我可以做到这一点,虽然 build.scala(和其他 scala 文件)最初并未被视为源代码,但我不得不稍微调整一下构建路径。然而,即使我已经为项目定义了 sbt main,eclipse IDE 和 compile 任务都会出错:

> compile
[error] .../myplay/project/Build.scala:2: not found: object keys
[error] import keys.Keys._
[error]        ^
[error] .../myplay/project/SbtAspectJ.scala:2: object Configurations is not a member of package sbt
[error] import sbt.Configurations.Compile
[error]            ^
[error] .../myplay/project/SbtAspectJ.scala:3: object Keys is not a member of package sbt
[error] import sbt.Keys._
[error]            ^
[error] three errors found

eclipse 项目在其引用库中既没有显示 main 也没有显示 aspectj-tools。但是,如果我给它一个伪造的版本(例如 0.12.4),重新加载会失败,所以它似乎正在使用 依赖关系。

所以,... 第一:这是正确的方法吗? 第二:如果是这样,为什么不添加库。 (第三:请不要让我错过了一些愚蠢的东西。)

【问题讨论】:

  • 真的,任何指针都会有帮助。

标签: sbt scala-ide sbt-aspectj


【解决方案1】:

如果您收到object Keys is not a member of package sbt 错误,那么您应该检查您是从基本目录而不是/project 目录运行sbt。

【讨论】:

    【解决方案2】:

    sbt-aspectj

    sbt-aspectj 似乎没有这样做,或者我看不到怎么做。

    我认为这是真正的问题。已经有一个插件可以完成这项工作,因此请尝试使其工作而不是摆弄构建。使用来自 build.scala 的插件有点棘手。 幸运的是,github 上有示例项目:

    import sbt._
    import sbt.Keys._
    import com.typesafe.sbt.SbtAspectj.{ Aspectj, aspectjSettings, compiledClasses }
    import com.typesafe.sbt.SbtAspectj.AspectjKeys.{ binaries, compileOnly, inputs, lintProperties }
    
    
    object SampleBuild extends Build {
      ....
    
      // precompiled aspects
      lazy val tracer = Project(
        "tracer",
        file("tracer"),
        settings = buildSettings ++ aspectjSettings ++ Seq(
          // stop after compiling the aspects (no weaving)
          compileOnly in Aspectj := true,
    
          // ignore warnings (we don't have the sample classes)
          lintProperties in Aspectj += "invalidAbsoluteTypeName = ignore",
    
          // replace regular products with compiled aspects
          products in Compile <<= products in Aspectj
        )
      )
    }
    

    您如何自行开发 SBT 项目?

    如果您对构建版本感兴趣,那么首先要去的地方是Getting Started 指南。具体来说,你的问题应该在.scala Build Definition page回答。

    我认为您希望您的构建使用"aspectj" % "aspectj-tools" % "1.0.6"。如果是这样,它应该包含在myplay/project/plugins.sbt 中,并且您的代码应该进入myplay/project/common.scala 或其他东西。如果您想使用 IDE,最好将其构建为 sbt 插件。这样你的代码就会进入src/main/scala。查看 sbt 插件结构示例中的 sbt/sbt-aspectj 或 sbt/sbt-assembly。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-06
      • 2019-07-17
      • 2014-08-05
      • 2011-02-22
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      相关资源
      最近更新 更多