I would do this via a profile, default value and surefire config, so
something like;

<profiles>
  <profile>
    <id>withJavaAgent</id>
    <properties>
      <myJavaAgent>-javaagent:C:\JARS\agent.jar</myJavaAgent>
    </properties>
  </profile>
</profiles>
<properties>
  <myJavaAgent></myJavaAgent>
</properties>
<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>${myJavaAgent}
-DtheGroup=${project.groupId} -DtheArtifact=${project.artifactId}</argLine>
  </configuration>
</plugin>

Then if you want to override on the command line it's; mvn test
-DmyJavaAgent="-javaagent:C:\JARS\agent.jar"
Or; mvn test -PwithJavaAgent

John


On Wed, 30 Mar 2022 at 06:45, Laurian Angelescu <angelescu.laur...@gmail.com>
wrote:

> I am working on a Java agent that instruments test suites and the code
> under test. The agent runs by invoking the following command on the command
> line:
>
> mvn test -DargLine="-javaagent:C:\JARS\agent.jar"
>
> The apache surefire plugin takes care of running the tests and pushing the
> -DargLine argument to the test JVM.
>
> But for hierarchical projects, I believe multiple JVMs are instantiated,
> one for each child package configured with pom.xml, as *mvn test *is
> recusively invoked downstream. I would like to keep track of each such
> child by capturing in mid-flight the group id, artifact id and version if
> it's available and passing this information into the agent.
>
> Is there a way to accomplish this data capture? Assume JUnit test suites.
>

Reply via email to