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

血红的双手。 提交于 2019-12-11 02:08:50

问题


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.

  • Note: I am using io.freefair.gradle:aspectj-plugin version 2.9.5 because my project is stuck using Gradle version 4.10.3.


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


回答1:


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"
}



回答2:


aspect is a plain old gradle configuration.

This means you can use all the notations described here:

  • https://docs.gradle.org/current/userguide/dependency_types.html#dependency_types
  • https://docs.gradle.org/current/userguide/declaring_dependencies.html
dependencies {
    aspect project(":my-aspect")
    aspect "com.example.foo:bar-aspect:1.0.0"
    aspect file("foo.jar")
}


来源:https://stackoverflow.com/questions/56221848/how-to-set-aspectpath-for-the-freefair-aspectj-gradle-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!