如何依赖这个Maven项目 [英] How to depend on this maven project

查看:94
本文介绍了如何依赖这个Maven项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目由三个子项目组成,我的父pom看起来像:

My projects consists of three sub-projects, and my parent pom looks like:

<groupId>com.bwort.core</groupId>
<artifactId>bwort</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>

<name>bwort</name>

<modules>
  <module>proj1</module>
  <module>proj2</module>
  <module>proj3</module>             
</modules>


现在,我的项目需要依赖下面的这个项目,该项目包括三个子项目,并带有一个父pom.特别是,它已经具有如下的父项: https://github.com/cmusphinx/sphinx4/blob/master/pom.xml


Now my project needs to dependent this project below, which comprises three subprojects, with a parent pom. In particular, it already has a parent as below: https://github.com/cmusphinx/sphinx4/blob/master/pom.xml

  <parent>
    <groupId>org.sonatype.oss</groupId>
    <artifactId>oss-parent</artifactId>
    <version>7</version>
  </parent>

  <groupId>edu.cmu.sphinx</groupId>
  <artifactId>sphinx4-parent</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

我的问题是,如何在父pom文件中声明依赖项?我可以在我的父pom中添加另一个模块:

My question is, how can I declare the dependency in my parent pom file? I can add another module to my parent pom:

<module>sphinx4</module>

但是由于该库已经定义了其自己的父级"oss-parent",那么如何使我的父级pom成为其父级呢?

But since this library already defined its own parent "oss-parent", then how can I make my parent pom as its parent?

我的项目依赖此项目的正确方法是什么?谢谢.

What's the right way for my project to depend on this project? Thank you.

我的pom.xml

 <project >
  <modelVersion>4.0.0</modelVersion>

   <parent>
     <groupId>com.bwort.core</groupId>
     <artifactId>bwort</artifactId>
     <version>0.0.1-SNAPSHOT</version>
   </parent>

    <artifactId>wikipedia</artifactId>
    <packaging>jar</packaging>


  <repositories>
       <repository>
           <id>snapshots-repo</id>
           <url>https://oss.sonatype.org/content/repositories/snapshots</url>
           <releases><enabled>false</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
       </repository>
    </repositories>

  <dependencies>

    <dependency>
        <groupId>edu.cmu.sphinx</groupId>
        <artifactId>sphinx4-core</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>edu.cmu.sphinx</groupId>
        <artifactId>sphinx4-data</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>

 </dependencies>   

</project>

推荐答案

如果您的pom.xml具有如下所示的内容,则它应该可以工作:

If your pom.xml has something like the following, it should work:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany.app</groupId>
    <artifactId>my-app</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>my-app</name>
    <url>http://maven.apache.org</url>
    <repositories>
        <repository>
            <id>snapshots-repo</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>edu.cmu.sphinx</groupId>
            <artifactId>sphinx4-core</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>edu.cmu.sphinx</groupId>
            <artifactId>sphinx4-data</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

这篇关于如何依赖这个Maven项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆