Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-aspectpath of external library(post compile weaving) #1110

Open
Kirill614 opened this issue May 3, 2024 · 6 comments
Open

-aspectpath of external library(post compile weaving) #1110

Kirill614 opened this issue May 3, 2024 · 6 comments

Comments

@Kirill614
Copy link

Hello, i am using io.freefair.aspectj.post-compile-weaving. When i have aspectj directory (with the aspect class) in root of my project - everything ok, but i need weave aspect from external library with my project sources, so i have this build.gradle file :

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.6.3'
    id 'io.spring.dependency-management' version '1.1.4'
    id "io.freefair.aspectj.post-compile-weaving" version "8.6"
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
    sourceCompatibility = '16'
    targetCompatibility = '16'
}

configurations {
    aspect
}

repositories {
    maven {
        url = uri("https://plugins.gradle.org/m2/")
    }
    mavenCentral()
    mavenLocal()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    aspect 'ru.vtb.smeg.lib:log-masker:1.3.1'
}

tasks.named('test') {
    useJUnitPlatform()
}

aspect 'ru.vtb.smeg.lib:log-masker:1.3.1' - its my external library which contains aspect class and all nesessary dependencies like aspectjrt, aspectjtools, aspectweaver. But when i build my project, i have this error:

java.lang.RuntimeException: Problem processing attributes in org/aspectj/ajdt/internal/compiler/CompilerAdapter.class
	at org.aspectj.weaver.bcel.BcelObjectType.ensureAspectJAttributesUnpacked(BcelObjectType.java:386)
	at org.aspectj.weaver.bcel.BcelObjectType.<init>(BcelObjectType.java:161)
	at org.aspectj.weaver.bcel.BcelWorld.buildBcelDelegate(BcelWorld.java:410)
	at org.aspectj.weaver.bcel.BcelWorld.addSourceObjectType(BcelWorld.java:487)
	at org.aspectj.weaver.bcel.BcelWorld.addSourceObjectType(BcelWorld.java:453)
	at org.aspectj.weaver.bcel.BcelWeaver.addAspectsFromJarFile(BcelWeaver.java:265)
	at org.aspectj.weaver.bcel.BcelWeaver.addLibraryJarFile(BcelWeaver.java:238)
	at org.aspectj.ajdt.internal.core.builder.AjBuildManager.initBcelWorld(AjBuildManager.java:868)
	at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:252)
	at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:188)
	at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:103)
	at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:47)
	at org.aspectj.tools.ajc.Main.run(Main.java:372)
	at org.aspectj.tools.ajc.Main.runMain(Main.java:250)
	at org.aspectj.tools.ajc.Main.main(Main.java:84)
Caused by: org.aspectj.weaver.BCException: malformed org.aspectj.weaver.PointcutDeclaration attribute (length:293)org.aspectj.weaver.BCException: Bad type signature org.aspectj.weaver.WeaverVersion
when batch building BuildConfig[null] #Files=0 AopXmls=#0

So how can i compile and weave aspect from external library taking into account that i need post compile weaving?

@larsgrefer
Copy link
Member

Your gradle configuration looks good to me. (Manually creating the aspect Configuration should not be necessary, but it should not hurt either)

Could you run the build with --info?
With which aspectj version was the aspect compiled?

@Lu-Whale
Copy link

I encountered the same issue. Did you solve it?

@atavanamir
Copy link

atavanamir commented Nov 21, 2024

I have the same error after upgrade to v8.11

@larsgrefer
Copy link
Member

Can someone of you provide an example project which I can use to debug this?

@pavelchuchma
Copy link

Reproduced on the latest versions: aspectj:1.9.22.1 and gradle plugin v8.11

It is enough to have aspectjtools library on aspectpath (in aspect gradle configuration)

like this:

aspect 'org.aspectj:aspectjtools:1.9.22.1'

I believe that ru.vtb.smeg.lib:log-masker:1.3.1 from the original description depends on aspectjtools lib.

I'm not sure if it is bug in user's lib or aspectj, it's up to you.

@larsgrefer
Copy link
Member

I was able to reproduce it. Apparently, the AspectJ compiler does not like it, if you feed itself into its aspectpath.

On the one hand, I'd argue that it makes no sense to have aspectjtools.jar on the aspectpath or as an dependency of an aspect.

But on the other hand, it's a bug in AspectJ to fail - this spectacularly - on this.

An aspect only needs to depend on aspectjrt, but not on aspectjtools or aspectweaver.

I'd suggest removing aspectjtools from the aspect path

larsgrefer added a commit that referenced this issue Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants