How configure aspectj compilation in playframework 2.1.1

吃可爱长大的小学妹 提交于 2019-12-13 01:09:12

问题


I have added to plugins.sbt this declaration

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

Now I would like to configure this plugin to compile my java controller classes using aspect library org.springframework:spring-aspects:3.1.4 as with aspectj-maven-plugin

I have set this configuration :

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
    )

}

But it does fail.

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

I am really a newbie with the sbt thing.

The plugin github page : https://github.com/sbt/sbt-aspectj


回答1:


Ok, I make it works, thanks to sbt mailing list, cf. https://groups.google.com/forum/?fromgroups=#!topic/simple-build-tool/MUXyfKigC7w

and the playframework mailing list also, cf. https://groups.google.com/forum/?fromgroups=#!topic/play-framework/RfJFEwVbUUk

It was not very hard in fact but something you can't see things.

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

Don't forget to add this in in plugins.sbt, with a new line separator between declaration

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


来源:https://stackoverflow.com/questions/16568349/how-configure-aspectj-compilation-in-playframework-2-1-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!