fedesilva / sbt-aspectj-runner

sbt plugin for running aspectj weaver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sbt-aspectj-runner

Build Status Download

This project contains two sbt plugins that automatically configure your build to perform Load-time weaving (LTW) with Aspectj when running your applicaction. These plugins enable you to seamlessly run both regular applications and play projects in development mode and ensure that your aspects will always be woven as expected. Only 0.13.x versions of sbt are currently supported.

Regular Projects (non-Play)

Configure

Add the aspectj-runner plugin to project/plugins.sbt, as well as our sbt-plugins repository. It should look like this:

resolvers += Resolver.bintrayRepo("kamon-io", "sbt-plugins")
addSbtPlugin("io.kamon" % "sbt-aspectj-runner" % "1.0.4")

Run

Just run!

Here is what the plugin will do depending on your fork settings:

  • fork in run := true: In this case, the forked process will run with the -javaagent:<jarpath> and that's all.
  • fork in run := false: Here we will load the application with a custom classloader called WeavingURLClassLoader that instantiates a weaver and weaves classes after loading, and before defining them in the JVM.

Play Projects

If try to run a Play application with LTW we will face some issues:

  • Play has a dynamic class-loading mechanism that loads dependency classes differently from classes in your source code in order to be able to reload changes in dev mode; This breaks some Load-time Weaving Requirements.
  • Also, by design, Play can not fork, hence setting javaOptions has no effect.

Having said that, let’s get into the rabbit hole!.

In order to achieve LTW support in Play's dev run, we will use the same approach used in Activator Inspect and sbt- echo, taking heavily inspiration from the latter.

The basic idea is: configure a custom classloader, in our case it will be the WeavingURLClassLoader rather than a java agent, and Play run will be set up to use this custom classloader. The magic is here.

Configure

Add the aspectj-play-runner plugin to project/plugins.sbt. It should look like this:

resolvers += Resolver.bintrayIvyRepo("kamon-io", "sbt-plugins")
addSbtPlugin("io.kamon" % "sbt-aspectj-play-runner" % "1.0.4")

and for play 2.6.x

resolvers += Resolver.bintrayIvyRepo("kamon-io", "sbt-plugins")
addSbtPlugin("io.kamon" % "sbt-aspectj-play-runner-26" % "1.0.4")

This plugin has been tested with Play 2.4.8, Play 2.5.10 and Play 2.6.5.

Run

Just execute run on the SBT console, everything should already be in place for you.

##Examples

There are full runnable examples.

About

sbt plugin for running aspectj weaver

License:Other


Languages

Language:Scala 100.0%