How to configure maven surefire to use jvm agent which is dependency?

I would like to configure the maven sure fire plugin to run jvm unit testing with an argument for a java agent. The agent jar file is obtained from the maven center, so I want maven to automatically determine the path to the agent jar file.

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12.4</version> <configuration> <argLine>-javaagent: How to reference an agent jar that is a depedency </argLine> </configuration> </plugin> 

How can I refer to the path to the agent, which is the project dependency, using the maven coordinates?

+6
source share
2 answers

You can copy one of your required cans to the destination. Then contact this bank at the command prompt.

Here is an example (using log4j, which is NOT a valid agent flag, but just shows an example):

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.5.1</version> <executions> <execution> <id>copy-agent</id> <phase>process-test-classes</phase> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> <outputDirectory>${project.build.directory}/agents</outputDirectory> <destFileName>my-special-agent.jar</destFileName> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12.4</version> <configuration> <argLine>-javaagent:${project.build.directory}/agents/my-special-agent.jar</argLine> </configuration> </plugin> 
+8
source

Use

Properties of mojo dependency plugin.

 <argLine>-javaagent:${org.springframework:spring-instrument:jar}</argLine> 
+1
source

All Articles