2

I am working on a multi module maven project, in which I need to run the same execution multiple times with only 1 or 2 different parameters. Basically, at the end of the build we are starting the resulting jar with some parameters, to execute a few simple build-in checks. The execution looks something like this:

<execution>
  <id>exec-build-in-checks</id>
  <phase>verify</phase>
  <goals>
    <goal>exec</goal>
  </goals>
  <configuration>
    <executable>${java.exe}</executable>
    <workingDirectory>${project.build.directory}</workingDirectory>
    <arguments>
      <argument>-classpath</argument
      <argument>${app.classpath}</argument>
      <argument>${app.mainClass}</argument>
      <argument>-someCommonArgument</argument>
      <argument>-anotherCommonArgument</argument>
      <argument>-someModuleDependentArgument</argument>
      <argument>-someUniqueArgument</argument>
    </arguments>
  </configuration>
</execution>

Now in the same module I have the same execution multiple times but with different values for someUniqueArgument. Cause of this I need to duplicate the whole execution block multiple times only to change one argument.
Also, I need the same execution in multiple modules but with a different value for someModuleDependentArgument.
So what I would like to do is to create an execution which I can call with different parameters form inside maven.
A solution I could think about is to use parameters inside the execution and change the value of those parameters in maven between the execution calls. However, I couldn't find a way to do this.
So is there a way to reuse the same execution with a few different parameter values?

EDIT:
Just to make it clear: The executions should be executed in the same build, so profiles or passing command line args is not a solution in this case.

Robert P
  • 9,398
  • 10
  • 58
  • 100
  • 1
    Actually, I think repeated execution blocks are as granular as you can get without using some other magic, like Gradle to programmatically replace variable values and re-execute. You could the execution blocks a little smaller with blocks of properties for every execution, but it's a brute force solution. – ingyhere Oct 01 '21 at 07:08
  • What is the reason you don't run this as JUnit test in the integration test phase? – J Fabian Meier Oct 01 '21 at 11:20
  • To be honest, the projects is a little special. It has grown over 20+ years and has just been migrated form an ant-based build to maven some time ago. So there are probably a few strange constructs in there which are hard to replace. The mentioned checks are only one of a few cases where we have such "duplicate executions" – Robert P Oct 01 '21 at 12:07

0 Answers0