0

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>

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>

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>

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.

EDITTED: My 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>
user697911
  • 10,043
  • 25
  • 95
  • 169
  • Tell me please if this could help you --> http://stackoverflow.com/questions/13487075/is-cmu-sphinx-available-via-maven – Iker Aguayo Aug 26 '15 at 06:07
  • It's definitely helpful. But after the repository URL and the dependency, I received this "Missing artifact edu.cmu.sphinx:sphinx4-data:jar:1.0-SNAPSHOT". I am using my own nexus repository. – user697911 Aug 26 '15 at 06:28
  • Please check if this jar is present on your nexus. If it is not there, specify it's repository in your pom.xml as mentioned in the above link given by Iker Aguayo. – asg Aug 26 '15 at 06:36
  • I tested it and it works adding the repository and the dependency to the pom.xml. So please check your pom.xml (and the settings.xml im .m2 folder) See the answer. – Iker Aguayo Aug 26 '15 at 06:43
  • I edited my post and added my pom.xml. What's strange is that, if I use my own setting.xml (my own nexus), it report the artifact missing error; if I remove the setting.xml in maven, it doesn't report an error. However, in both cases, I got the same ~/.m2/repository/org/sonatype/oss/oss-parent/7/oss-parent-7.pom, without the actual jar file. Any idea of the reason? – user697911 Aug 26 '15 at 07:15

2 Answers2

2

No you don't add modules to your pom which refer to other peoples modules.

When executing mvn install and or mvn deploy it will copy the artifacts defined in the pom.xml files into the local or a remote repository. So hopefully the project you want to depend on is available in maven central.

what I would suggest is to add a dependency management section into your parent pom.xml:

<properties>
  <sphinx.version>1.0-SNAPSHOT</sphinx>
</properties>
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>edu.cmu.sphinx</groupId>
      <artifactId>sphinx4-module1</artifactId>
      <version>${sphinx.version}</version>
    </dependency>
    <dependency>
      <groupId>edu.cmu.sphinx</groupId>
      <artifactId>sphinx4-module2</artifactId>
      <version>${sphinx.version}</version>
    </dependency>
  </dependencies>
</dependencyManagement>

in the pom.xml of one of your own modules add that dependency you need into the dependencies section: Note the version is now defined in the parent.

  <dependencies>
    <dependency>
      <groupId>edu.cmu.sphinx</groupId>
      <artifactId>sphinx4-module2</artifactId>
    </dependency>
  </dependencies>

I would recommend to not use -SNAPSHOT versions of other people applications - it often causes build failures depending on when the snapshot was created and when maven retrieves it.

If sphinx is not in a repository you first need to do a mvn install locally

And I would recommend the maven tutorials:

they explain quite a lot as well :)

wemu
  • 7,952
  • 4
  • 30
  • 59
1

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>
Iker Aguayo
  • 3,980
  • 4
  • 37
  • 49
  • Yes, I edited, similar to yours. POM doesn't report an error, but when I check ~/.m2/repository/org/sonatype/oss/oss-parent/7/, it only shows oss-parent-7.pom file, without a jar. Without a Jar. why doesn't it report an error? – user697911 Aug 26 '15 at 07:03
  • Did you do, mvn package?? Because I did and the dependencies are downloaded – Iker Aguayo Aug 26 '15 at 07:06
  • I can see that they are downloaded from the message on the screen "Downloaded: https://oss.sonatype.org/content/repositories/snapshots/edu/cmu/sphinx/sphinx4-core/1.0-SNAPSHOT/sphinx4-core-1.0-20150630.174404-9.jar (1184 KB at 614.7 KB/sec) Downloaded: https://oss.sonatype.org/content/repositories/snapshots/edu/cmu/sphinx/sphinx4-data/1.0-SNAPSHOT/sphinx4-data-1.0-20150630.174256-9.jar (36900 KB at 3456.9 KB/sec)", but I can't see it in ~/.m2/repository/org/sonatype/oss/oss-parent/7/, only the three files "oss-parent-7.pom oss-parent-7.pom.sha1 _remote.repositories ". No error seen too. – user697911 Aug 26 '15 at 07:21
  • There dependencies are in ~/.m2/repository/edu/cmu/sphinx and now there are added to your projects as dependencies. Test if you can use the api of these dependencies on your projects, if yes, your problem is solve – Iker Aguayo Aug 26 '15 at 07:24
  • Yah, it's there! But why when I use my own nexus setting, it can't download? In my pom.xml, it's " jar". This shouldn't matter. Right? – user697911 Aug 26 '15 at 07:38
  • I do not know, maybe an error in the Nexus config. See this, http://stackoverflow.com/questions/14333577/adding-maven-nexus-repo-to-my-pom-xml But this should be another question :) – Iker Aguayo Aug 26 '15 at 07:42