我正在尝试将一个 jar 从我的本地存储库复制到另一个项目中,如下所述:
http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html
但是,我的 jar 是作为“具有依赖项的 jar”从 maven-assembly-plugin 中出来的,它将常规 jar 和组装好的 jar 放在我的本地存储库中。 jar 名称类似于:
example-test-0.0.1-SNAPSHOT-jar-with-dependencies.jar
如果我手动复制,我可以在 repo 中找到它并使用它。我认为让 maven 复制它是个好主意,所以我使用了上面描述的依赖复制目标。
但是我无法让它工作,所以它复制了“具有依赖关系的 jar” jar。
这是 pom 的样子:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>my.group</groupId>
<artifactId>example-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>libs</outputDirectory>
<destFileName>somename.jar</destFileName>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
我试图将类型设置为“jar-with-dependencies”,但这没有用。只有当我让类型为“jar”时它才有效,但它会复制常规的未组装的 jar。任何想法如何解决这一问题?
最佳答案
如果您有这样的 Artifact :
example-test-0.0.1-SNAPSHOT-jar-with-dependencies.jar
你想像这样引用它:
<artifactItem>
<groupId>my.group</groupId>
<artifactId>example-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
<classifier>jar-with-dependencies</classifier>
<overWrite>true</overWrite>
<outputDirectory>libs</outputDirectory>
<destFileName>somename.jar</destFileName>
</artifactItem>
例子在这里:
<artifactItem>
<groupId>[ groupId ]</groupId>
<artifactId>[ artifactId ]</artifactId>
<version>[ version ]</version>
<type>[ packaging ]</type>
this---><classifier> [classifier - optional] </classifier>
<overWrite>[ true or false ]</overWrite>
<outputDirectory>[ output directory ]</outputDirectory>
<destFileName>[ filename ]</destFileName>
</artifactItem>
关于Maven 依赖插件复制带有依赖项的 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28975230/