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 https://github.com/eveoh/gradle-aspectj for details:

buildscript { 
    repositories { 
        maven { 
            url "https://maven.eveoh.nl/content/repositories/releases" 
        } 
    } 
    
    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 https://github.com/breskeby/gradleplugins/blob/0.9-upgrade/aspectjPlugin/aspectJ.gradle#L29):

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', [:]) 
    
    ajnature.setValue('org.eclipse.ajdt.ui.ajnature'); 
    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.

Last blog articles:
Hello Ruby: Dobrodružné programování
Edison EdBlocks: Using remote control
Edison 2.0 received!
JS debug: visually compare two objects or JSONs in browser
4 tips to return multiple values

Last tweets: