[英]Can my maven project import dependencies from a pom inside a dependency?
我有一个maven项目,说“ MyProject”,它使用另一个项目作为我写的普通maven依赖性,说“ MyDependency”。 MyDependency是一个使用其他依赖项(例如springframework,apache-commons,apache-camel等)的Maven项目。
问题是这样的。 我希望MyProject在MyDependency中看到传递依赖,而不必再次将它们添加到pom文件中。 我尝试使用maven-dependency插件和maven-jar插件来生成一个jar,如下所示,该jar中包含所有依赖项,但没有结果。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>compile</includeScope>
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>lib/</Class-Path>
</manifestEntries>
</archive>
<finalName>core-${project.version}</finalName>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
有什么办法吗? 还是我的问题全错了?
MyProject可以使用MyDependency中的依赖项。 Maven自动解决传递依赖。 您无需进行任何复制。 您可以使用mvn dependency:list
来查看项目所使用的工件的整个mvn dependency:list
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.