1

我已将这个声明添加到 plugins.sbt

addSbtPlugin("com.typesafe.sbt" % "sbt-aspectj" % "0.9.0")

现在我想配置这个插件来使用方面库 org.springframework:spring-aspects:3.1.4 编译我的 java 控制器类,就像使用 aspectj-maven-plugin

我已经设置了这个配置:

import sbt._
import Keys._
import play.Project._
import com.typesafe.sbt.SbtAspectj._
import com.typesafe.sbt.SbtAspectj.AspectjKeys._

object ApplicationBuild extends Build {

    val appDependencies = Seq(javaCore)

    val main = play.Project(appName, appVersion, appDependencies).settings(
        AspectjKeys.verbose in Aspectj := true,
        AspectjKeys.showWeaveInfo in Aspectj := true,
        AspectjKeys.inputs in Aspectj <+= compiledClasses
    )

}

但它确实失败了。

[error] Reference to undefined setting: 
[error] 
[error]   aspectj:inputs from aspectj:inputs

我真的是 sbt 的新手。

插件github页面:https ://github.com/sbt/sbt-aspectj

4

1 回答 1

3

好的,我让它工作了,感谢 sbt 邮件列表,cf。https://groups.google.com/forum/?fromgroups=#!topic/simple-build-tool/MUXyfKigC7w

和 playframework 邮件列表,参见。https://groups.google.com/forum/?fromgroups=#!topic/play-framework/RfJFEwVbUUk

其实这不是很难,但有些东西是你看不到的。

import sbt._
import Keys._
import play.Project._
import com.typesafe.sbt.SbtAspectj._
import com.typesafe.sbt.SbtAspectj.AspectjKeys._

object ApplicationBuild extends Build {

    val appDependencies = Seq(javaCore, filters)

    val main = play.Project(appName, appVersion, appDependencies)
            .settings(aspectjSettings: _*)
            .settings(
                    libraryDependencies += "org.springframework" % "spring-aspects" % "3.1.4.RELEASE",
                    libraryDependencies += "org.springframework.security" % "spring-security-aspects" % "3.1.4.RELEASE",
                    sourceLevel := "-1.7",
                    verbose in Aspectj := false,
                    showWeaveInfo in Aspectj := false,
                    inputs in Aspectj <+= compiledClasses,
                    binaries in Aspectj <++= update map { report =>
                        report.matching(
                                moduleFilter(organization = "org.springframework", name = "spring-aspects")
                                || moduleFilter(organization = "org.springframework.security", name = "spring-security-aspects")
                        )
                    },
                    products in Compile <<= products in Aspectj,
                    products in Runtime <<= products in Compile
                )
}

不要忘记在 plugins.sbt 中添加这个,声明之间有一个新的行分隔符

addSbtPlugin("com.typesafe.sbt" % "sbt-aspectj" % "0.9.0")
于 2013-05-17T09:50:36.220 回答