Coder Social home page Coder Social logo

sbt-aspectj-runner's Introduction

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.bintrayIvyRepo("kamon-io", "sbt-plugins")
addSbtPlugin("io.kamon" % "sbt-aspectj-runner" % "1.0.1")

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.1")

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

Run

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

##Examples

There are full runnable examples.

sbt-aspectj-runner's People

Contributors

dpsoft avatar ivantopo avatar crypticmind avatar smagnacco avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.