Error while using aspectj with Scala

619 Views Asked by At

I am having an application in scala. I need to use AOP for one of the functionality. I used the plugin sbt-aspectj . Everything is working fine when I run using the sbt console. However, I am not able to make it work when using the executable jar. I tried the the sample code provided in the sbt-aspect git page. But, I am getting the errors as

[warn] warning incorrect classpath: D:\source\jvm\modules\scala\frameworks\aspectjTracer\target\scala-2.11\classes
[warn] Missing message: configure.invalidClasspathSection in: org.aspectj.ajdt.ajc.messages
[error] error no sources specified

.

[trace] Stack trace suppressed: run 'last aspectjTracer/aspectj:ajc' for the full output.
[error] (aspectjTracer/aspectj:ajc) org.aspectj.bridge.AbortException: ABORT
[error] Expected project ID
[error] Expected configuration
[error] Expected ':' (if selecting a configuration)
[error] Expected key
[error] Not a valid key: aspectjTracker (similar: aspectjSource, aspectj-source, aspectjDirectory)
[error] last aspectjTracker/aspectj:ajc
[error]  

My Build.scala is given below :

object frameworkBuild extends Build {

  import Dependencies._
  val akkaV = "2.3.6"
  val sprayV = "1.3.1"
  val musterV = "0.3.0"

  val common_settings = Defaults.defaultSettings ++
    Seq(version := "1.3-SNAPSHOT",
      organization := "com.reactore",
      scalaVersion in ThisBuild := "2.11.2",
      scalacOptions ++= Seq("-unchecked", "-feature", "-deprecation"),

      libraryDependencies := frameworkDependencies ++ testLibraryDependencies,
      publishMavenStyle := true,

    )

  connectInput in run := true

  lazy val aspectJTracer = Project(
    "aspectjTracer",
    file("aspectjTracer"),
    settings = common_settings ++ aspectjSettings ++ Seq(
      // input compiled scala classes
      inputs in Aspectj <+= compiledClasses,

      // ignore warnings
      lintProperties in Aspectj += "invalidAbsoluteTypeName = ignore",
      lintProperties in Aspectj += "adviceDidNotMatch = ignore",

      // replace regular products with compiled aspects
      products in Compile <<= products in Aspectj
    )
  )
  // test that the instrumentation works
  lazy val instrumented = Project(
    "instrumented",
    file("instrumented"),
    dependencies = Seq(aspectJTracer),
    settings = common_settings ++ aspectjSettings ++ Seq(
      // add the compiled aspects from tracer
      binaries in Aspectj <++= products in Compile in aspectJTracer,

      // weave this project's classes
      inputs in Aspectj <+= compiledClasses,
      products in Compile <<= products in Aspectj,
      products in Runtime <<= products in Compile
    )
  )
  lazy val frameworks = Project(id = "frameworks", base = file("."), settings = common_settings).aggregate( core, baseDomain,aspectJTracer,instrumented)

  lazy val core = Project(id = "framework-core", base = file("framework-core"), settings = common_settings)
  lazy val baseDomain = Project(id = "framework-base-domain", base = file("framework-base-domain"), settings = common_settings).dependsOn(core,aspectJTracer,instrumented)
}

Does anyone know how to fix this? I posted this in the sbt-aspectj github page and waiting for a response there as well. But I am in a little hurry to fix this. Your help will be really appreciated.

1

There are 1 best solutions below

4
On BEST ANSWER

Finally the problem is resolved. I had added javaagent in the build.scala. But, while running with the sbt-one-jar, it was not taking that jar. So I have manually provided the javaagent as the aspectweaver jar file and it worked. However, it is almost taking 3-4 minutes to start the jar file with the aspect.

Sometime it is even taking 15 min to start the jar file due to the aspectjwaver. I am not sure if this is problem with aspectj or sbt-one-jar, I guess its with the one-jar. has anyone else faced the same issue ? I don't see any activity in sbt-one-jar, so asking it here.