AspectJ weaving with gradle 5.2.1 problem

Hi gradle forum,

I want to ask you for help with my aspectJ weaving in gradle problem.

I was using gradle 3.4.1 and everything worked perfectly. For AspectJ weaving I used similar code to answer of this topic Stackoverflow - gradle + aspectj.

But now I upgraded to the newest Gradle 5.2.1, Android plugin 3.3.2, so I had to stop using compile configuration and switched it to implementation.
Snippet of my code:

> def androidSdk = android.getAdbExecutable().parent + "/../platforms/" + android.compileSdkVersion + "/android.jar" //adding path to android jar
>
> def iajcClasspath = configurations.implementation.asPath + ";" + androidSdk //combining path from implementation configuration and path to android jar
>
> project.file('classes-woven').mkdirs() //making dir for woven classes
>
> configurations.implementation.dependencies.each { dep -> //adding path to classes.jar inside aar's from projects in implementation configuration
>
>     if (dep.hasProperty("dependencyProject")) {
>             iajcClasspath += ":" + dep.dependencyProject.buildDir + "/intermediates/bundles/${pathInsideAar}/classes.jar"
>     }
>
> }
>
> ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath) //defining task iajc
>
> ant.iajc( //weaving aspects into classes, stored in classes-woven dir
>         destDir: 'classes-woven',
>         showWeaveInfo: "true",
>         Xlint: "ignore",
>         aspectPath: configurations.aspects.asPath,
>         sourceRootCopyFilter: "**/*.java",
>         inpath: inpathDir,
>         classpath: iajcClasspath
> )

And there comes the problem - when I try to build it, it says, there is error “Resolving configuration ‘implementation’ directly is not allowed” on line “def iajcClasspath = configurations.implementation.asPath + “;” + androidSdk”.

I was trying to debug it, so I create my own configuration, which implements “implementation”, but when I build it, it says “Cannot choose between the following:
configurations of project xxx”, which I was unable to remove.

I can’t figure out, where is the difference between old and new gradle and what to do to weav aspectj into my code.

Thank you in advance,

Petr

Instead trying to access the configuration directly, configurations.implementation, would finding it by name, configurations.findByName('implementation'), or get by name, configurations.getByName('implementation'), work?

Hi Justin,

really thanks for your advice. I tried to build it with both suggested methods, but unfortunately it didn’t help, these methods probably will return “implementation” and it is the same situation as I experienced before (error: Resolving configuration ‘implementation’ directly is not allowed).

Don’t you have any other idea, please? I tried to google it of course, but nothing helped… Or any “official” source, where is this error mentioned to know exactly, what does it cause? I can’t find anything…

Thank you,

Petr

Hi @lohi,

I see the error you are talking about and its in the default configuration class.

I am not a gradle team dev so I don’t have insight into it. I was able to get the path though through a custom config:

configurations {
    customConfiguration.extendsFrom(implementation)
}
task customTask {
    doLast {
        println(configurations.customConfiguration.asPath)
    }
}

Could you go down the route of a custom configuration and use that instead of the provided ones from gradle/android?

Hi Justin,

thank you for your reply again. Unfortunately, I tried it this way - I mentioned it in my first post as:

I create my own configuration, which implements “implementation”, but when I build it, it says “Cannot choose between the following:
configurations of project xxx”, which I was unable to remove.

So I just moved from one error to another… I found this post on stack overflow (Android Studio 3.0 Compile Issue (Cannot choose between Configurations) - Stack Overflow) with the same error and tried to solve it as in “verified answer”

implementation project(path: ':lp_messaging_sdk', configuration: 'default')

But it lead me to third error - something about duplicity of one of modules (I don’t have the project here, so I can’t give you the error).

So I know, that it’s little bit confusing, but I need solve one of these errors to be able to compile my project again…:slight_smile:

Thank you in advance really really much!

Petr

Sorry @lohi I don’t have much more to contribute then. The sample I gave (custom config) works with a brand new android studio based project. I unfortunately haven’t run into the other problems.

Hi @lohi,

I needed to do something similar and made it work with a buildSrc plugin. Attached is the project. There is an aspectj task that depends on java compile task. There is a separate sourceset/configuration for aspectj files, particular .aj source.

you can see the output in the buildDir/aspectj directory.

Maybe that can help you out. sorry its not ant based.

JT

ajplugin.zip (59.8 KB)