0

I have the following project structure:

Parent
-- Module A
-- Module B
    -- Module C
    -- Module D

Parent has the following properties:

<properties>
        <ModuleA.version>1.8</ModuleA.version>
</properties>

In module C, I am specifying dependency of A, using ${ModuleA.version}.

Module D depends on Module C, which in turn depends on Module A. Now, when I am running mvn clean install on Module D, considering that they share the same parent, I am expecting that the properties defined in parent would be available and hence ModuleA.version would be resolved to 1.8 and used.

However, the command is failing with the error:

The following artifacts could not be resolved: ModuleA:jar:${ModuleA.version}

Can someone help me with what I am missing here.

In all the modules I am specifying parents correctly. That is: Module C and Module D mentions Module B as parent. Module B and Module A mentions Parent as parent.

Actual POM's below: Parent:

<groupId>com.dummy</groupId>
<artifactId>parent</artifactId>
<version>0.15-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Parent</name>

<properties> <store-version>0.19-SNAPSHOT</store-version> 
             <data-version>0.16-SNAPSHOT</data-version>

</properties>

Data POM

<parent>
<groupId>com.dummy</groupId>
<artifactId>parent</artifactId>
<version>0.15-SNAPSHOT</version>
<relativePath>../../parent</relativePath>

Store POM:

<parent>
        <groupId>com.dummy</groupId>
        <artifactId>parent</artifactId>
        <version>0.15-SNAPSHOT</version>
        <relativePath>../../parent</relativePath>
    </parent>

<dependency>
            <groupId>com.dummy</groupId>
            <artifactId>data</artifactId>
            <version>${data-version}</version>
            <scope>compile</scope>
        </dependency>

When I use mvn clean install for Store project, it finds Data version and gives no errors.

Source POM

<parent>
        <groupId>com.dummy</groupId>
        <artifactId>parent</artifactId>
        <version>0.15-SNAPSHOT</version>
        <relativePath>../parent</relativePath>
    </parent>
<artifactId>source</artifactId>
    <packaging>pom</packaging>
    <version>0.6-SNAPSHOT</version>

Source API POM

<parent>
        <groupId>com.dummy</groupId>
        <artifactId>source</artifactId>
        <version>0.6-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

<dependency>
            <groupId>com.dummy</groupId>
            <artifactId>store</artifactId>
            <version>${store.version}</version>
            <scope>compile</scope>
        </dependency>

Source API builds fine, finds proper versions.

Source WS

<parent>
        <groupId>com.dummy</groupId>
        <artifactId>source</artifactId>
        <version>0.6-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

 <dependency>
        <groupId>com.dummy</groupId>
        <artifactId>source-api</artifactId>
        <version>${project.version}</version>
    </dependency>

When I try to build source-ws, the build fails with error, ${data-version} not found.

Logan
  • 2,445
  • 4
  • 36
  • 56

1 Answers1

0

I created the following projects according to your description:

+- P
+- A  -> parent P
+- B  -> parent P
+- C  -> parent B, depends on A
+- D  -> parent B, depends on C

P's POM

<groupId>so.55374493</groupId>
<artifactId>P</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
    <ModuleA.version>1.8</ModuleA.version>
    <revision>1.8</revision>
</properties>

<modules>
    <module>../A</module>
    <module>../B</module>
</modules>

A's POM

<parent>
    <groupId>so.55374493</groupId>
    <artifactId>P</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../P</relativePath>
</parent>

<artifactId>A</artifactId>
<version>${ModuleA.version}</version>
<!-- use the following instead to omit: 
     "[WARNING] 'version' contains an expression but should be a constant." -->
<!-- <version>${revision}</version> -->

B's POM

<parent>
    <groupId>so.55374493</groupId>
    <artifactId>P</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../P</relativePath>
</parent>

<artifactId>B</artifactId>
<packaging>pom</packaging>

<modules>
    <module>../C</module>
    <module>../D</module>
</modules>

C's POM

<parent>
    <groupId>so.55374493</groupId>
    <artifactId>B</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../B</relativePath>
</parent>

<artifactId>C</artifactId>

<dependencies>
    <dependency>
        <groupId>so.55374493</groupId>
        <artifactId>A</artifactId>
        <version>${ModuleA.version}</version>
    </dependency>
</dependencies>

D's POM

<parent>
    <groupId>so.55374493</groupId>
    <artifactId>B</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../B</relativePath>
</parent>

<artifactId>D</artifactId>

<dependencies>
    <dependency>
        <groupId>so.55374493</groupId>
        <artifactId>C</artifactId>
        <version>${project.version}</version>
    </dependency>
</dependencies>

mvn install on P and D both succeed (where A at the former prints the well-known [WARNING] 'version' contains an expression but should be a constant., which can be resolved by ${revision} since Maven 3.5).

Can you confirm that your POMs look equally in terms of <parent>s, <properties> (except ${revision}), <version>s and <dependencies>?

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107