Create multi-module Maven projects in Eclipse

Trying to create a maven project in mcl-eclipse.

Parent 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>parent</groupId>
  <artifactId>proj1</artifactId>
  <version>${myversion}</version>
  <packaging>pom</packaging>
  <properties>
   <myversion>1.0.0</myversion>
  </properties>
  <modules>
   <module>child1</module>
   <module>child2</module>
  </modules>
</project>

Child-Module 1 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>proj1</artifactId>
    <groupId>parent</groupId>
    <version>${myversion}</version>
  </parent>
  <groupId>parent</groupId>
  <artifactId>child1</artifactId>
  <version>${myversion}</version>
</project>

Kids Module 2 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>proj1</artifactId>
    <groupId>parent</groupId>
    <version>${myversion}</version>
  </parent>
  <groupId>parent</groupId>
  <artifactId>child2</artifactId>
  <version>${myversion}</version>
  <dependencies>
   <dependency>
    <groupId>parent</groupId>
    <artifactId>child1</artifactId>
    <version>${myversion}</version>
    <type>jar</type>
    <scope>compile</scope>
   </dependency>
  </dependencies>
</project>

If I use mvn clean install on the command line from the parent folder, I can build find. All projects have been successfully completed.

But in eclipse I keep getting the error for Child Module 2 pom.xml

Description Resource Path Location Type
parent:child1:1.0.0:jar Missing:
----------
1) parent:proj1:pom:${myversion}
----------
1 required artifact is missing.

for artifact: 
  parent:proj1:pom:${myversion}

from the specified remote repositories:
  central (http://repo1.maven.org/maven2, releases=true, snapshots=false)
 pom.xml /child2 line 1 Maven Problem

I need to achieve two things 1. The maven property determines the version in the parent pom file. 2. Use this property to determine the version in all child modules.

What should I do? I am stuck. Please, help.

I am using Eclipse Galileo with m2Eclipse

+3
source share
1 answer

, (, , , . MNG-624). , POM :

<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>parent</groupId>
  <artifactId>proj1</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>
  <modules>
   <module>child1</module>
   <module>child2</module>
  </modules>
</project>

POM 1. /project/parent/version 2. <version> ( ). 3. ${project.version} .

<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>
  <parent>
    <artifactId>proj1</artifactId>
    <groupId>parent</groupId>
    <version>1.0.0</version>
  </parent>
  <groupId>parent</groupId>
  <artifactId>child2</artifactId>
  <!--version>${myversion}</version--> <!-- Inherited -->
  <dependencies>
   <dependency>
    <groupId>parent</groupId>
    <artifactId>child1</artifactId>
    <version>${project.version}</version> <!-- use the built-in property here -->
    <!--type>jar</type--> <!-- This is a default, you can omit it -->
    <!--scope>compile</scope--> <!-- This is a default, you can omit it -->
   </dependency>
  </dependencies>
</project>

Maven 3.1.

.

+1

Source: https://habr.com/ru/post/1753813/


All Articles