This issue is driving me crazy. I have a parent that defines a bunch dependency versions using dependency management. Then I have a child module that uses these dependencies. The problem is that while I can build the child module no problem, if I try to run any maven task on the parent, it gives me the error saying that the child's pom is bad because I haven't specified versions for its dependencies.

Parent pom:

<?xml version="1.0" encoding="UTF-8"?>
<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.myproject</groupId>
  <artifactId>parent</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>parent</name>

  <modules>
    <module>common</module>
  </modules>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <maven.compiler.release>11</maven.compiler.release>

    <lombok.version>1.18.28</lombok.version>
    <protobuf.version>3.21.12</protobuf.version>
    <jackson-version>2.13.5</jackson-version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson-version}</version>
      </dependency>
      <dependency>
        <groupId>com.google.protobuf</groupId>
        <artifactId>protobuf-java</artifactId>
        <version>${protobuf.version}</version>
      </dependency>
      <dependency>
        <groupId>com.google.protobuf</groupId>
        <artifactId>protobuf-java-util</artifactId>
        <version>${protobuf.version}</version>
      </dependency>
      <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  
  <build>...</build>
  <distributionManagement>...</distributionManagement>
  <repositories>...</repositories>
  
</project>

Child module pom:

<?xml version="1.0" encoding="UTF-8"?>
<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.myproject</groupId>
    <artifactId>parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>

  <artifactId>common</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>common</name>
  <description>Common module</description>

  <properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java-util</artifactId>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
    </dependency>
  </dependencies>

  <build>...</build>
  
</project>

Error (on mvn clean on the parent, for example):

[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project mx.myproject:common:1.0.0-SNAPSHOT (/#####/myproject/common/pom.xml) has 4 errors
[ERROR]     'dependencies.dependency.version' for com.fasterxml.jackson.core:jackson-databind:jar is missing. @ line 26, column 17
[ERROR]     'dependencies.dependency.version' for com.google.protobuf:protobuf-java:jar is missing. @ line 30, column 17
[ERROR]     'dependencies.dependency.version' for com.google.protobuf:protobuf-java-util:jar is missing. @ line 34, column 17
[ERROR]     'dependencies.dependency.version' for org.projectlombok:lombok:jar is missing. @ line 38, column 17
  • I am using the latest stable maven version 3.9.5 (no additional m2 config).
  • I've tried cleaning my m2 cache and deleting the artifacts related to the project, but it didn't help.
  • If I move or copy the dependencyManagement section to the child module, the issue disappears. However, the idea is to have dependency management declared only once in the parent, so all child modules would inherit the dependency versions automatically.

Does anyone have any idea what might be wrong? I would really appreciate any help that might be provided in this matter.

0

There are 0 answers