Asad
Asad

Reputation: 15

Maven child project build failure

Data-Layer pom file:

<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/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>  
   <parent>
      <groupId>com.ehr</groupId>
      <artifactId>parentEHR</artifactId>
      <version>0.0.1-SNAPSHOT</version>
   </parent>

   <artifactId>Data-Layer</artifactId>
   <packaging>jar</packaging>
</project>

Core-layer pom file

<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/xsd/maven-4.0.0.xsd">

   <modelVersion>4.0.0</modelVersion>
   <parent>
      <groupid>com.ehr</groupid>
      <artifactId>parentEHR</artifactId>
      <version>0.0.1-SNAPSHOT</version>
   </parent>

   <artifactId>Core-Layer</artifactId>
   <packaging>jar</packaging>

   <dependencies>
      <dependency>
         <groupId>com.ehr</groupId>
         <artifactId>Data-Layer</artifactId>
         <version>0.0.1-SNAPSHOT</version>
      </dependency>
   </dependencies>

</project>

Error:

Failed to execute goal on project Core-Layer: Could not resolve dependencies for project com.ehr:Core-Layer:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.ehr:Data-Layer:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for com.ehr:Data-Layer:jar:0.0.1-SNAPSHOT: Could not find artifact com.ehr:parentEHR:pom:0.0.1-SNAPSHOT -> [Help 1]

The above error occurs.

Can any one help me?

Upvotes: 1

Views: 1962

Answers (3)

Arpit Aggarwal
Arpit Aggarwal

Reputation: 29316

Assuming parentEHR is your parent project and Core-Layer, Data-Layer are child projects of the same. pom.xml of each should look like as:

parentEHR - pom.xml

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ehr</groupId>
    <artifactId>parentEHR</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>../Data-Layer</module>
        <module>../Core-Layer</module>
    </modules>
</project>

Core-Layer - pom.xml

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ehr</groupId>
    <artifactId>Core-Layer</artifactId>
    <packaging>jar</packaging>
    <parent>
        <groupId>com.ehr</groupId>
        <artifactId>parentEHR</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../parentEHR</relativePath>
    </parent>
</project>

Data-Layer - pom.xml

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ehr</groupId>
    <artifactId>Data-Layer</artifactId>
    <packaging>jar</packaging>
    <parent>
        <groupId>com.ehr</groupId>
        <artifactId>parentEHR</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../parentEHR</relativePath>
    </parent>
</project>

Upvotes: 1

Davio
Davio

Reputation: 4737

You need to make sure that modules (children) are defined in the parent as well as modules defining their parent in their own pom.

In parent pom:

<modules>
   <module>Core-Layer</module>
   <module>Data-Layer</module>
</modules>

And then start a build from within the parent folder, which will build the modules in order (from top to bottom).

Upvotes: 1

Bovas Chinnathambi
Bovas Chinnathambi

Reputation: 1

If your dependency project is built successfully, then maven should find that artifact in your local repository, when building the current project(in your case, 'Core-Layer').

  1. Make sure you build your data-layer project with the command 'mvn install'.This command updates your local repository with the artifact.
  2. If the maven build is successful, verify the artifact in your local repository.(Generally ${current_user}.m2\repositories\com\ehr).
  3. If the artifact of data-layer is available there, then maven will read it from there, whenever you are referring it with that artifact id.

Upvotes: 0

Related Questions