我们有一个使用maven-antrun-plugin
来运行下载的JAR的配置文件。如何在maven-antrun-plugin中使用插件依赖范围中的依赖项?
附件A:(这部作品)
大家可以参考使用属性${maven.dependency.com.foobar.target-jar.jar.path}
(Can I use the path to a Maven dependency as a property?)下载JAR。但是在这个解决方案中,自定义依赖项和存储库信息不仅限于配置文件的范围。
<project>
...
<repositories>
<repository>
<id>thirdparty</id>
<name>Third Party</name>
<url>
[URL for the repository that holds the target JAR]
</url>
<layout>default</layout>
</repository>
</repositories>
...
<dependencies>
<dependency>
<groupId>com.foobar</groupId>
<artifactId>target-jar</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
...
<profiles>
<profile>
<id>runJARprofile</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<inherited>false</inherited>
<executions>
<execution>
<id>run-jar</id>
<phase>package</phase>
<configuration>
<target name="runJar" fork="true">
<java jar="${maven.dependency.com.foobar.target-jar.jar.path}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
...
</project>
附件B:(还没有得到它的工作)
在这里,我们提出的依赖性和资源库信息到配置文件。 Maven成功下载了工件,但我们不再知道如何通过属性来引用它。
<project>
...
<profiles>
<profile>
<pluginRepositories>
<repository>
<id>thirdparty</id>
<name>Third Party</name>
<url>
[URL for the repository that holds the target JAR]
</url>
<layout>default</layout>
</repository>
</pluginRepositories>
...
<id>runJARprofile</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<inherited>false</inherited>
<dependencies>
<dependency>
<groupId>com.foobar</groupId>
<artifactId>target-jar</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>run-jar</id>
<phase>package</phase>
<configuration>
<target name="runJar" fork="true">
<java jar="${?????}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
...
</project>
我不知道我理解的问题/问题。首先定义的属性“maven.dependency.com.foobar.target-jar.jar.path”在哪里? – Tunaki
@Tunaki看起来像第一个例子,它是通过'$ {maven.dependency.com.foobar.target-jar.jar.path}'从'pom'的''dependencies>'中取出的,当第二个例子想要使用添加到''的''。我认为这个问题是“你怎么能在插件的依赖范围中使用_maven-antrun-plugin_中的依赖项?”。 –
mkobit
基于[此链接](http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html),属性格式为'$ {maven.dependency.com.foobar.target-jar .jar.path}'已被弃用,所以我们应该使用'$ {com.foobar:target-jar:jar}'来代替。在图表A中试过,但它仍然有效,但在图表B中仍然不起作用。 – thn929