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.
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?
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 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.
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.
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.