I would do that in a dedicated module, use the Maven Dependency Plugin to unpack the artifact "under test" during the generate-test-sources
phase, then weave the classes and finally run the tests.
Let me try to illustrate what I mean. Let's imagine the following project structure:
.
|-- pom.xml
`-- some-module // this is the module that we want to weave
|-- pom.xml // but only for testing purpose
`-- ...
So my suggestion is to do something like this:
.
|-- pom.xml
|-- some-module
| |-- pom.xml
| `-- ...
`-- test-module // we're going to weave the classes here because we don't want
|-- pom.xml // the tracing aspect to be packaged in the "production" jar
`-- ...
The idea is to have an additional "test-module" where we would unpack the artifact that we want to test so that we can weave its classes without affecting the "real" production jar.
To do so, declare a dependency on the module under test and use dependency:unpack
to unpack the classes into target/classes
before invoking the AspectJ plugin to weave the "main" classes.