【问题标题】:How to resolve the path to an artifact in a maven pom without being a project dependency?如何在不依赖项目的情况下解决 maven pom 中工件的路径?
【发布时间】: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


    【解决方案1】:

    我建议使用dependency:copy 将JAR 复制到/target 的某个位置。然后你可以将该路径添加到 antrun 或 exec 插件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-31
      • 2012-10-30
      • 2015-02-07
      • 1970-01-01
      • 1970-01-01
      • 2022-12-06
      • 1970-01-01
      相关资源
      最近更新 更多