【发布时间】:2021-05-16 22:25:30
【问题描述】:
我想知道是否可以在不将该工件作为项目依赖项的情况下解析 Maven 工件的路径?
我要做的是通过 exec-maven-plugin 或 maven-antrun-plugin 执行外部 java 代码生成器:
<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>
所以这里的重点是如何解决 ${de.powerstat.fb:generator:1.0-SNAPSHOT} 的 jar 路径而不将其作为整个项目的依赖项?同样使用exec:java 目标也不是解决方案,因为这个似乎有不同的问题,但那是another question。
使用 antrun 插件我遇到了同样的问题:
<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>
那么问题又是如何解决modulepath="${de.powerstat.fb:generator:1.0-SNAPSHOT}"?
使用目标为dependency:properties 的maven 依赖插件的解决方案在这种情况下将不起作用。
【问题讨论】:
标签: maven maven-3 exec-maven-plugin maven-antrun-plugin