GithubHelp home page GithubHelp logo

sbt-aspectj-runner's Introduction

sbt-aspectj-runner

Build Status Maven Central

This project contains two sbt plugins to perform Load-time weaving (LTW) with Aspectj in a fast and easy way in our sbt projects. With these plugins we will be able to do a run in development mode in play based projects seamlessly. Only versions 0.13.x and upper of sbt are currently supported.

##Sbt Projects

###Configure

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

addSbtPlugin("io.kamon" % "aspectj-runner" % "0.1.3")

###Run

To run your application with LTW support, the only thing we need is to call run or run-main tasks. These use the same underlying settings for the regular run task, but also add the configuration needed to instrument your application, depending whether the task should fork or not.

To run the default or discovered main class use:

aspectj-runner:run

To run a specific main class:

aspectj-runner:run-main my.awesome.package.MainClass

Additionally, we can run tests with LTW. For that we need to include the test-specific settings in our build:

kamon.aspectj.sbt.AspectjRunner.testSettings

and finally

aspectj-runner-test:run

We have two scenerios:

  • 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. This enables load-time weaving support in environments where no weaving agent is available.

##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.
  • If we manage to fork Play somehow and run with -javaagent:<jarpath> attached, we'll lose dev mode reloading.

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 allow the class loader to be configured). The magic is here.

###Configure

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

addSbtPlugin("io.kamon" % "aspectj-play-runner" % "0.1.3")

the code above is for Play 2.4.x, in the case of Play 2.3.x, it should look like this:

addSbtPlugin("io.kamon" % "aspectj-play-23-runner" % "0.1.3")

###Run

aspectj-play-runner:run

###Overriding configuration file

System properties can be used to force a different config source:

  • config.resource: aspectj-runner:run -Dconfig.resource=whatever.conf
  • config.file: aspectj-runner:run -Dconfig.file=conf/environments/dev/other.conf
  • config.url:aspectj-runner:run -Dconfig.url=http://site.com/my/awesome/configuration.conf

These system properties specify a replacement for application.conf, not an addition.

###Enjoy!

##Examples

There are full runnable examples.

Branches to look

The master branch is where the development of the latest version lives on and the the main difference with the Play-2.3.x branch is the play version.

sbt-aspectj-runner's People

Contributors

dpsoft avatar crypticmind avatar smagnacco avatar

Watchers

Peter Mortier avatar James Cloos avatar  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.