mconner
mconner

Reputation: 1556

How do you do develop an SBT project, itself?

Background: I've got a Play 2.0 project, and I am trying to add something to do aspectj weaving using aspects in a jar on some of my classes (Java). (sbt-aspectj doesn't seem to do it, or I can't see how). So I need to add a custom task, and have it depend on compile. I've sort of figured out the dependency part. However, because I don't know exactly what I'm doing, yet, I want to develop this using the IDE (I'm using Scala-IDE). Since sbt projects (and therefore Play projects) are recursively defined, I assumed I could:

  1. Add the eclipse plugin to the myplay/project/project/plugins.sbt
  2. Add the sbt main jar (and aspectj jar) to myplay/project/project/build.sbt:

    libraryDependencies ++= Seq( "org.scala-sbt" % "main" % "0.12.2", "aspectj" % "aspectj-tools" % "1.0.6" )

  3. Drop into the myplay/project

  4. Run sbt, run the eclipse task, then import the project into eclipse as a separate project.

I can do this, though the build.scala (and other scala files) aren't initially considered source, and I have to fiddle with the build path a bit. However, even though I've got the sbt main defined for the project, both eclipse IDE and the compile task give errors:

> 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

The eclipse project shows neither main nor aspectj-tools in its referenced-libraries. However, if I give it a bogus version (e.g. 0.12.4), reload fails, so it appears to be using the dependency.

So,... First: Is this the proper way to do this? Second: If so, why aren't the libs getting added. (Third: please don't let this be something dumb that I missed.)

Upvotes: 3

Views: 1012

Answers (2)

Eugene Yokota
Eugene Yokota

Reputation: 95674

sbt-aspectj

sbt-aspectj doesn't seem to do it, or I can't see how.

I think this is the real issue. There's a plugin already that does the work, so try making it work instead of fiddling with the build. Using plugins from build.scala is a bit tricky. Luckily there are sample projects on 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
    )
  )
}

How do you do develop an SBT project, itself?

If you're interested in hacking on the build still the first place to go is the Getting Started guide. Specifically, your question should be answered in .scala Build Definition page.

I think you want your build to utilize "aspectj" % "aspectj-tools" % "1.0.6". If so it should be included in myplay/project/plugins.sbt, and your code should go into myplay/project/common.scala or something. If you want to use IDE, you have have better luck with building it as a sbt plugin. That way your code would go into src/main/scala. Check out sbt/sbt-aspectj or sbt/sbt-assembly on example of sbt plugin structure.

Upvotes: 1

tmarthal
tmarthal

Reputation: 1528

If you are getting the object Keys is not a member of package sbt error, then you should check that you are running sbt from the base directory, and not the /project directory.

Upvotes: 7

Related Questions