AspectJ and Gradle

In recent post I have described dynamical way of AspectJ waving. Today I have tried compile time way. So no JAVA_TOOL_OPTIONS is necessary.

Gradle build

See for details:

buildscript {
repositories {
maven {
url ""

dependencies {
classpath "nl.eveoh:gradle-aspectj:1.5"

project.ext {
aspectjVersion = '1.8.6'

apply plugin: 'java'

//eclipse support
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'

apply plugin: 'aspectj'

Eclipse build

In Eclipse install through Help->Eclipse Marketplace plugin “AspectJ Development tools”. Then add into Gradle (adjusted version of

eclipse.project.file.withXml { xmlProvider->
def projectDescription = xmlProvider.asNode()
def xmlparser = new XmlParser()

def builders = projectDescription.buildSpec[0]
def ajbuilder = xmlparser.createNode(builders, 'buildCommand', [:])
xmlparser.createNode(ajbuilder, 'name', [:]).setValue('org.eclipse.ajdt.core.ajbuilder')
xmlparser.createNode(ajbuilder, 'arguments', [:]);

def natures = projectDescription.natures[0]
def ajnature = xmlparser.createNode(null, 'nature', [:])
natures.children().add(0, ajnature)

Then execute gradle eclipse, refresh workspace and run Project->Clean->All projects. Then start your project and waving should be already done. You can check existence of AspectJ builder in context menu of project, Properties->Builders->AspectJ Builder.


One thought on “AspectJ and Gradle

  1. Pingback: Ultimate AspectJ method tracing | Jaroslav Kubos

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s