2

I have a Gradle 7.3.3 aspect library and a Gradle 7.3.3 project which consumes that library. I am applying the io.freefair.aspectj.post-compile-weaving Gradle plugin in the project.

plugins {
    id 'io.freefair.aspectj.post-compile-weaving' version '6.3.0'
}

I am then adding the library to the project as an aspect dependency.

dependencies {
    aspect 'com.example:my-aspect-lib:0.0.1'
}

Aside from the library aspects that I want to weave post-compile, the project itself has aspects that I want Spring AOP to handle at runtime. Those aspects must not be woven post-compile. However, the default behavior of post-compile-weaving is to weave all aspects in the project.

I have tried quite a few different iterations of ajc configuration, including messing with compilerArgs, but so far I have not been able to exclude the project aspects from post-compile weaving.

compileJava {
    ajc {
        options {
            aspectpath.minus files()
            aspectpath.setFrom configurations.aspect
        }
    }
}

Is it possible to exclude aspects with the post-compile-weaving plugin?

I also asked this question here but as of this post have not yet received any response.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
Aaron B
  • 53
  • 3
  • 1
    Welcome to SO. Do yourself a favour and provide an [MCVE](https://stackoverflow.com/help/mcve) when asking questions. The benefit will be better and quicker answers. In this case, for example, I know a lot about AspectJ and also know how to build with Maven, but I am not a Gradle user. I think I can look into it and help you, if I have an example project reproducing your problem, but I do not feel so inclined to prepare an example multi-module project from scratch and learn Gradle just in order to help you. – kriegaex Feb 15 '22 at 02:26

1 Answers1

1

This is a general answer, not specific to Freefair or even Gradle:

The AspectJ compiler has an undocumented option -xmlConfigured by which you can specify an XML file similar to the aop.xml file used to configure load-time weaving (LTW). The best overview of how to use it you can find in the AspectJ documentation bug I raised in back in 2014. Just read through it and follow some of the links I provided.

If the Freefair post-compile plugin supports some way of adding custom compiler options, I think this is what you want, because in the XML file you can explicitly specify which aspects the compiler should use. All others, it will ignore.

Feel free to let me know, if you have any concrete problems applying this solution - but please only, if you have an MCVE, ideally on GitHub, for me. Thank you.


Update: See also my other answers concerning -xmlConfigured:

That should give you enough information to adapt it to Gradle.

kriegaex
  • 63,017
  • 15
  • 111
  • 202