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

Accessing to aspect from class doesnt work after rebuild #825

Open
hohserg1 opened this issue Jul 5, 2023 · 1 comment
Open

Accessing to aspect from class doesnt work after rebuild #825

hohserg1 opened this issue Jul 5, 2023 · 1 comment

Comments

@hohserg1
Copy link

hohserg1 commented Jul 5, 2023

How to reproduce:

  1. create new project
    build.gradle: https://gist.github.com/hohserg1/fa5cface77c0613ff2421bb3a9f31d27
    gradle-wrapper.properties: distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
  2. add source code: https://gist.github.com/hohserg1/ae21ca49f281dfebe6c7431372c37bfd
  3. execute gradlew build
    got compilation error: https://gist.github.com/hohserg1/26cd155afdca7e9dadba3d171fc2f04d
  4. change source code(remove accessing to aspect from class): https://gist.github.com/hohserg1/1c7b32834c0e2b2233e3efcff97d78b3
  5. execute gradlew build
    compilation successed
  6. try run
> Task :Main.main()
from Main
from TestAspect
  1. change source code back: https://gist.github.com/hohserg1/ae21ca49f281dfebe6c7431372c37bfd
  2. execute gradlew build
    compilation successed
  3. try run
> Task :Main.main()
from Main
from TestAspect
true
  1. execute gradlew clean
  2. execute gradlew build
    got compilation error: https://gist.github.com/hohserg1/26cd155afdca7e9dadba3d171fc2f04d
  3. repeat from step 5

Expected behavior:
Compilation must be successed from clean project

I'm not sure, if its really need to access to aspect's fields/methods, but kinda bug

Also reproducing at 6.5.1 plugin version

@larsgrefer
Copy link
Member

TL;DR: The post-compile-weaving plugin is not meant to compile *.aj sources directly, try io.freefair.aspectj

With your current setup, you are using both javac and ajc to compile your source files.

First, javac runs as it usually would with gradles "compileJava" task. But javac can only read *.java files, so it cannot find org.example.aspect.TestAspect. After removing the reference to org.example.aspect.TestAspect javac can compile the .java file just fine.

After this, an additional action added to the compileJava task executes ajc, which will successfully compile both source files.

Once the aspect has been compiled once by ajc, javac can now also see the .class file of the aspect.
So from then on, javac can compile the .java file with access to the aspect.

When dealing with .aj files, you should try the io.freefair.aspectj plugin instead, which adds an additional sourceDir src/main/aspectj where you can put .aj and .java files, which will then be compiled by ajc only.

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

2 participants