Skip to content

Fix weaving of already compiled classes when source code is absent#240

Closed
slachiewicz with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-weaving-compiled-classes
Closed

Fix weaving of already compiled classes when source code is absent#240
slachiewicz with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-weaving-compiled-classes

Conversation

Copilot AI commented Oct 26, 2025

Copy link
Copy Markdown

Fix weaving of already compiled classes when there is no source code

Fixes #217

Problem

The AspectJ Maven Plugin would skip weaving entirely when no source files were provided via <sources/>, even when weaveDirectories or weaveDependencies were configured. This prevented users from:

  • Compiling classes with maven-compiler-plugin
  • Applying bytecode modifications with another plugin
  • Then weaving those modified classes with AspectJ

Solution

Modified the hasSourcesToCompile() method in AbstractAjcCompiler.java to check for the presence of weaveDirectories or weaveDependencies in addition to source files. When these are configured, the plugin will proceed with weaving even if no source files are present.

Changes Made

  • Core Fix: Added hasWeavableContent() helper method that returns true if either weaveDirectories or weaveDependencies are configured
  • Integration Test: Created WeaveDirectoriesNoSources test to verify the plugin executes correctly when <sources/> is empty but weaveDirectories is configured

Testing

  • ✅ All unit tests pass
  • ✅ All integration tests pass
  • ✅ New integration test validates the fix
  • ✅ Code review completed
  • ✅ Security scan passed (CodeQL found no vulnerabilities)

The fix is minimal and focused, allowing the plugin to proceed with weaving when weavable content is configured, without altering any other functionality.

Original prompt

This section details on the original issue you should resolve

<issue_title>Weaving of already compiled classes is skipped when there is no source code</issue_title>
<issue_description>The example given here doesn't work:
https://dev-aspectj.github.io/aspectj-maven-plugin/examples/weaveDirectories.html

This is because already compiled classes will be overridden with the configuration they give.

In my use case, I need to compile classes, apply modifications to their bytecode using another plugin entirely, and then weave them. My modifications are lost because they are overridden with the weaving that comes from the source code.

The example here seems to offer a solution:
https://dev-aspectj.github.io/aspectj-maven-plugin/examples/includeExclude.html

I tried using an empty source tag, <sources/>, but then the weaving is skipped entirely.

The only work-around that works for me is to exclude part of the source code, using <excludes>...</excludes> for example, while leaving at least one class to avoid the weaving being skipped entirely.
</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Modified hasSourcesToCompile() to also check for weaveDirectories and weaveDependencies.
When these are configured, the plugin will proceed with weaving even if no source files are present.
Added integration test WeaveDirectoriesNoSources to verify the fix.

Co-authored-by: slachiewicz <6705942+slachiewicz@users.noreply.github.com>
Copilot AI requested a review from slachiewicz October 26, 2025 10:13
@slachiewicz

Copy link
Copy Markdown
Member

@copilot continue with fix

Copilot AI commented Oct 26, 2025

Copy link
Copy Markdown
Author

@copilot continue with fix

Fix is complete! All tasks have been finished:

✅ Code review completed - no actionable issues found (the "Azpect" naming follows existing test conventions)
✅ Security scan passed - CodeQL found no vulnerabilities
✅ All unit tests passing
✅ All integration tests passing

The fix allows weaving to proceed when weaveDirectories or weaveDependencies are configured, even with empty <sources/>. The plugin now correctly handles the use case of weaving pre-compiled classes that have been modified by other plugins.

Copilot AI changed the title [WIP] Fix weaving of already compiled classes when source code is absent Fix weaving of already compiled classes when source code is absent Oct 26, 2025
@slachiewicz
slachiewicz deleted the copilot/fix-weaving-compiled-classes branch November 11, 2025 09:30
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

Successfully merging this pull request may close these issues.

Weaving of already compiled classes is skipped when there is no source code

2 participants