sbt-aspectj icon indicating copy to clipboard operation
sbt-aspectj copied to clipboard

Migrating to the new version of sbt-aspectj

Open hasansozer opened this issue 7 years ago • 4 comments

I am trying to compile and run a tool, which is using an old version of sbt-aspectj (com.typesafe.sbtaspectj" % "sbt-aspectj" % "0.5.3"). I updated the plugins.sbt file to switch to the new version ("com.lightbend.sbt" % "sbt-aspectj" % "0.11.0"). I updated the build file as well. The original build file can be found in this link: https://github.com/samira-t/Bita/blob/master/project/Build.scala

Hereby, I updated the import statements as follows:

mport com.lightbend.sbt.SbtAspectj import com.lightbend.sbt.AspectjKeys.{ aspectjInputs, aspectjBinaries, aspectjWeave }

Then I updated the library dependencies as follows:

libraryDependencies ++= Seq( "com.typesafe.akka" %% "akka-actor" % "2.4.1", "org.scalatest" %% "scalatest" % "2.2.4" % "test", "org.scala-lang" % "scala-reflect" % "2.11.7", "org.scala-lang.modules" %% "scala-xml" % "1.0.4" ),

The following definition does not work since "inputs in Aspectj" is apparently not defined anymore:

inputs in Aspectj <<= update map { report => report.matching(moduleFilter(organization = "com.typesafe.akka", name = "akka-actor")) },

So, I changed it as follows (hoping that this value in AspectjKeys is representative):

aspectjInputs <<= update map { report => report.matching(moduleFilter(organization = "com.typesafe.akka", name = "akka-actor")) },

I changed the last two lines for using the instrumented versions as well (hoping that they are comparable to the use of AspectjPlugin.useInstrumentedClasses and AspectjPlugin.useInstrumentedJars):

fullClasspath in Test <<= SbtAspectj.aspectjUseInstrumentedClasses(Test), fullClasspath in Runtime <<= SbtAspectj.aspectjUseInstrumentedClasses(Runtime)))

Assuming that the above modifications are correct, the part that I am really puzzled with is the definition of an aspect filter as copied below:

aspectFilter in Aspectj := { (jar, aspects) => { if (jar.name.contains("akka-actor") ) aspects filter (jar => (jar.name.startsWith("Actor"))) else Seq.empty[File] } },

Apperrently such a filter is not defined in the version. I also could not find a representative definition.

hasansozer avatar Dec 18 '17 21:12 hasansozer

Hi, sorry for the late response. Let's see if this can help you:

  • aspectjInputs still needs to be scoped to the Aspectj configuration, despite it's prefix. i.e.: aspectjInputs in Aspectj <<= update map { ... }
  • Your use case looks very very similar to this specific example: https://github.com/sbt/sbt-aspectj/blob/master/src/sbt-test/weave/external/build.sbt. It's about instrumenting an external JAR file and then reusing it later in a different module. You might be interested on mimic part of it.
  • You are using a very old version of SBT, 0.12.x, the latest version of this plugin it's only being tested with SBT 0.13.5+ and 1.0.x. Upgrading SBT to the latest will also force you to change the <<= syntax though.

alonsodomin avatar Jan 02 '18 11:01 alonsodomin

Thank you for help. Scoping leads to a compile error in my case (keyword Aspectj is not recognized); however, I will study and try to mimic the statements in the example build file. I will also try to upgrade the SBT version.

hasansozer avatar Jan 04 '18 06:01 hasansozer

Hi, Im trying to write a skinny poc in scala (2.11.11 version) and sbt 1.0.4 of aspectj and it just doesn't work for me. can someone kindly link me to such come skinny code example that works? Thanks in advanced

alexfel avatar May 27 '18 18:05 alexfel

@hasansozer I am using aspectjInputs in Aspectj += (aspectjCompiledClasses in Aspectj).value,

roopak-agarwal avatar Jul 13 '18 09:07 roopak-agarwal