我的maven项目可以从依赖项中的pom导入依赖项吗?

时间:2017-05-17 06:25:26

标签: java maven maven-3 maven-plugin dependency-management

我有一个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>

有没有办法做到这一点?或者我的问题都错了?

1 个答案:

答案 0 :(得分:2)

MyProject可以使用MyDependency中的依赖项。 Maven自动解决传递依赖性。你不需要做任何复制。您可以使用mvn dependency:list来查看项目使用的整个工件列表。

相关问题