In order to perform AspectJ runtime weaving, an agent is required. Here we are using the agent (spring-instrument-3.0.3.RELEASE) provided by the Springframework. So for surefire we have to use a command line argument javaagent: that specifies the JAR file containing the agent. To keep the build portable we copy that artifact to the build directory first using the maven-dependency-plugin.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<plugin>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
      <execution>
          <id>copy</id>
          <phase>process-sources</phase>
          <goals>
              <goal>copy</goal>
          </goals>
          <configuration>
              <artifactItems>
                  <artifactItem>
                      <groupId>org.springframework</groupId>
                      <artifactId>spring-instrument</artifactId>
                      <version>3.0.3.RELEASE</version>
                  </artifactItem>
              </artifactItems>
          </configuration>
      </execution>
  </executions>
</plugin>

We have to pass in the weaving agent to surefire.

1
2
3
4
5
6
<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
      <argLine>-javaagent:${project.build.directory}/dependency/spring-instrument-3.0.3.RELEASE.jar</argLine>
  </configuration>
</plugin>

Comments