Skip to content

Commit

Permalink
build: add exec-maven-plugin and agent config mode profiles
Browse files Browse the repository at this point in the history
for running main class/tests with customized java (agent) options conveniently
  • Loading branch information
oldratlee committed Jul 13, 2023
1 parent 7a69b72 commit 2084e27
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
64 changes: 61 additions & 3 deletions main-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
<artifactId>main-runner</artifactId>

<properties>
<exec.mainClass>io.foldright.study.main.Main</exec.mainClass>

<agent.opt.hello>-javaagent:${io.foldright.study:hello-agent:jar}</agent.opt.hello>
<dopt.enable.agent.hello>-Denable.hello.agent=true</dopt.enable.agent.hello>
<agent.opt.world>-javaagent:${io.foldright.study:world-agent:jar}</agent.opt.world>
<dopt.enable.agent.world>-Denable.world.agent=true</dopt.enable.agent.world>
</properties>

<dependencies>
Expand All @@ -33,12 +37,66 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<argLine>@{argLine} ${agent.opt.hello} ${agent.opt.world}</argLine>
<executable>${java.home}/bin/java</executable>
<arguments>
<argument>-Xms256m</argument>
<argument>-ea</argument>
<argument>-Duser.language=en</argument>
<argument>-Duser.country=US</argument>

<argument>-classpath</argument>
<classpath/>

<argument>${exec.mainClass}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<!-- agent config mode profiles -->
<profile>
<id>enable-hello-world-agents</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{argLine}
${agent.opt.hello} ${dopt.enable.agent.hello}
${agent.opt.world} ${dopt.enable.agent.world}
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<arguments>
<argument>-Xms256m</argument>
<argument>-ea</argument>
<argument>-Duser.language=en</argument>
<argument>-Duser.country=US</argument>

<argument>${agent.opt.hello}</argument>
<argument>${dopt.enable.agent.hello}</argument>
<argument>${agent.opt.world}</argument>
<argument>${dopt.enable.agent.world}</argument>

<argument>-classpath</argument>
<classpath/>

<argument>${exec.mainClass}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
<project.reporting.outputEncoding>${project.build.sourceEncoding}</project.reporting.outputEncoding>
<maven.javadoc.skip>true</maven.javadoc.skip>
<maven.deploy.skip>true</maven.deploy.skip>
<!-- need argLine to use `@{argLine}`(e.g. `maven-surefire-plugin`) -->
<argLine/>

<spotbugs.annotations.version>4.7.3</spotbugs.annotations.version>
<jsr305.version>3.0.2</jsr305.version>
Expand All @@ -74,7 +76,6 @@
<!-- testing dependencies versions -->
<junit5.version>5.9.3</junit5.version>
<kotest.version>5.6.2</kotest.version>
<argLine/>
</properties>

<dependencies>
Expand Down Expand Up @@ -426,6 +427,15 @@
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.0</version>
</plugin>
<plugin>
<!--
https://www.mojohaus.org/exec-maven-plugin/
https://www.mojohaus.org/exec-maven-plugin/exec-mojo.html
-->
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down

0 comments on commit 2084e27

Please sign in to comment.