Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(pom): wrong inheritance of version and scope from root DepManagement in parent dependencies #7539

Open
DmitriyLewen opened this issue Sep 18, 2024 Discussed in #7537 · 1 comment · May be fixed by #7541
Open

bug(pom): wrong inheritance of version and scope from root DepManagement in parent dependencies #7539

DmitriyLewen opened this issue Sep 18, 2024 Discussed in #7537 · 1 comment · May be fixed by #7541
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.
Milestone

Comments

@DmitriyLewen
Copy link
Contributor

Description

We need to correctly inherit some fields from the root DepManagement in parent dependencies:

  • always use version from root DepManagement and don't use properties from parent.
  • overwrite scope only if parent dependency doesn't use scope

Example:
root 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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.example</groupId>
        <artifactId>example-parent</artifactId>
        <version>4.0.0</version>
        <relativePath>./parent/pom.xml</relativePath>
    </parent>

    <groupId>com.example</groupId>
    <artifactId>child-depManagement-in-parent</artifactId>
    <version>1.0.0</version>


    <properties>
        <api.version>1.0.1</api.version>
        <api2.version>1.0.2</api2.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.example</groupId>
                <artifactId>example-api</artifactId>
                <version>${api.version}</version>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.example</groupId>
                <artifactId>example-api2</artifactId>
                <version>${api2.version}</version>
                <scope>runtime</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

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>org.example</groupId>
    <artifactId>example-parent</artifactId>
    <version>4.0.0</version>
    <packaging>pom</packaging>

    <properties>
        <api.version>4.0.1</api.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>example-api</artifactId>
            <version>${api.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>example-api2</artifactId>
        </dependency>
    </dependencies>
</project>

mvn result:

[INFO] com.example:child-depManagement-in-parent:jar:1.0.0
[INFO] +- org.example:example-api:jar:1.0.1:compile
[INFO] \- org.example:example-api2:jar:1.0.2:runtime

Discussed in #7537

@DmitriyLewen DmitriyLewen added the kind/bug Categorizes issue or PR as related to a bug. label Sep 18, 2024
@DmitriyLewen DmitriyLewen self-assigned this Sep 18, 2024
@DmitriyLewen
Copy link
Contributor Author

always use version from root DepManagement and don't use properties from parent.
overwrite scope only if parent dependency doesn't use scope

After investigation I realized that this is incorrect.
For parents we need to inherit DependencyManagement and Properties as non-rootDepManagements.
In this case we will be correctly overwrite empty scopes/version, use properties, etc.

@knqyf263 knqyf263 added this to the v0.57.0 milestone Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
Status: No status
2 participants