javagradlebuild.gradleaspectjfreefair-aspectj

How to set "-aspectpath" for the FreeFair AspectJ Gradle Plugin?


I am trying to use an AspectJ Annotation that is in a Library, that I am pulling into my project. My project uses Gradle, so I am attempting to use FreeFair AspectJ Gradle Plugin.

I need to be able to set the AspectJ -aspectpath argument, to the Library Dependency that Gradle is pulling in.

FreeFair, does not seem to have much Documentation, mainly just Sample Code.

In their sample code, I see that I can use this to set the -aspectpath to a local "project":

aspect project(":aspectj:aspect")

Does anyone know how to set the -aspectpath to an external library dependency?

I created an example Project and put it on GitHub: freefair-aspectpath-external-library.


Update: I have created a bug for this: https://github.com/freefair/gradle-plugins/issues/46


Solution

  • Thanks to @larsgrefer, who provided the answer in the GitHub Issue (46).

    For the io.freefair.aspectj.compile-time-weaving plugin 2.9.5 the configuration is named "aspects" instead of "aspect".

    The following fixed the issue:

    aspects project(":aspectj:aspect")
    

    The full build file resembles:

    buildscript {
        repositories {
            maven { url "https://plugins.gradle.org/m2/" }
        }
        dependencies {
            // 2.9.5 for use with Gradle 4.10.3.
            classpath "io.freefair.gradle:aspectj-plugin:2.9.5"
        }
    }
    
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'idea'
    
    apply plugin: "io.freefair.aspectj.compile-time-weaving"
    aspectj.version = '1.9.3'
    
    group 'xyz.swatt'
    version '1.0.0-SNAPSHOT'
    
    sourceCompatibility = 1.8
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
    
        ///// SWATT ///// https://mvnrepository.com/artifact/xyz.swatt/swatt
        compile group: 'xyz.swatt', name: 'swatt', version: '1.12.0'
        aspect "xyz.swatt:swatt:1.12.0"
    }