【发布时间】:2017-05-17 06:25:25
【问题描述】:
我有一个 maven 项目说“MyProject”,它使用另一个项目作为普通的 maven 依赖项,说我写的“MyDependency”。 MyDependency 是一个maven 项目,它使用了springframework、apache-commons、apache-camel 等其他依赖项。
问题是这样的。我希望 MyProject 可以看到 MyDependency 中的传递依赖项,而不必再次将它们添加到 pom 文件中。我尝试了 maven-dependency 插件和 maven-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使用任何特定范围? -
@BurhaanAdam 你的意思是你想要一个包含所有依赖项的存档吗?或者您无法编写代码,因为您的 IDE 未检测到依赖项并且您无法访问类?
标签: java maven maven-3 maven-plugin dependency-management