mavenmaven-3exec-maven-pluginmaven-antrun-plugin

How to resolve the path to an artifact in a maven pom without being a project dependency?


I would like to know if it is possible to resolve the path for a maven artifact without having this artifact as a dependency in the project?

What I am trying to do is to execute an external java code generator via exec-maven-plugin or maven-antrun-plugin:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>3.0.0</version>

  <configuration>        
    <executable>java</executable>            
    <arguments> 
      <argument>-jar ${de.powerstat.fb:generator:1.0-SNAPSHOT}</argument>
      <argument>de.powerstat.fb.generator.CodeGenerator</argument>

      <argument>${fb.hostname}</argument>
      <argument>${fb.port}</argument>
      <argument>${fb.username}</argument>
      <argument>${fb.password}</argument>
      <argument>${project.build.directory}</argument>
    </arguments>
  </configuration>

  <executions>
    <execution>
      <phase>generate-sources</phase>
      <goals>
        <goal>exec</goal>
      </goals>
    </execution>
  </executions>
</plugin>

So the point here is how to solve the jars path for ${de.powerstat.fb:generator:1.0-SNAPSHOT} without having it as a dependency of the whole project? Also using the exec:java goal is not a solution, because this one seems to have different problems, but thats another question.

Using the antrun plugin I come to the same problem:

<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>3.0.0</version>
  <executions>
    <execution>
      <phase>generate-sources</phase>
      <configuration>
        <target>
          <java fork="true" failonerror="true" module="de.powerstat.fb.generator" modulepath="${de.powerstat.fb:generator:1.0-SNAPSHOT}">
            <arg value="${fb.hostname} ${fb.port} ${fb.username} ${fb.password} ${project.build.directory}"/>
          </java>
        </target>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>

So question is again how to solve the modulepath="${de.powerstat.fb:generator:1.0-SNAPSHOT}"?

Solutions that use the maven dependency plugin with the goal dependency:properties will not work in this scenario.


Solution

  • I suggest to use dependency:copy to copy the JAR to some place in /target. Then you can add that path to the antrun or exec plugin.