首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的maven项目可以从依赖项中的pom导入依赖项吗?

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

Stack Overflow用户
提问于 2017-05-17 14:25:26
回答 1查看 763关注 0票数 1

我有一个名为"MyProject“的maven项目,它使用另一个项目作为我编写的普通maven依赖项"MyDependency”。MyDependency是一个maven项目,它使用了其他依赖项,如springframework、apache-commons、apache-camel等。

问题是这样的。我希望MyProject能够看到MyDependency中的传递依赖项,而不必将它们再次添加到pom文件中。我尝试了maven-dependency插件和maven-jar插件,以生成一个jar,如下所示,其中包含所有依赖项,但没有结果。

代码语言:javascript
复制
<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>

代码语言:javascript
复制
<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>

有没有办法做到这一点?还是我的问题全错了?

EN

回答 1

Stack Overflow用户

发布于 2017-05-17 14:28:35

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44017106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档