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

Coursier ignores overridden properties in child POM #2906

Open
ppkarwasz opened this issue Dec 21, 2023 · 2 comments
Open

Coursier ignores overridden properties in child POM #2906

ppkarwasz opened this issue Dec 21, 2023 · 2 comments

Comments

@ppkarwasz
Copy link

ppkarwasz commented Dec 21, 2023

In the Apache Log4j project we support multiple versions of the same library (in different Maven modules).

In order to do that, in the parent POM we specify the version of the library via a Maven property:

<properties>
  <slf4j.version>2.0.9</slf4j.version>
</properties>
<dependencyManagement>
  <dependencies>
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
      </dependency>
  </dependencies>
</dependencyManagement>

and we overwrite the property value in the child POM:

<properties>
  <slf4j.version>1.7.25</slf4j.version>
</properties>

This works very well with Maven, since the "inheritance assembly" phase precedes the "model interpolation" phase (cf. Maven Model Builder).

However, as reported by one of our users (cf. apache/logging-log4j2#2065) this doesn't work with Coursier: in the above example Maven with choose version 1.7.25 while Coursier will choose version 2.0.9.

@gatisnolv
Copy link

I think you meant that you specify <slf4j.version>2.0.9</slf4j.version> and not <slf4j.api>2.0.9</slf4j.api> in the Parent POM, so in your redacted example:

<properties>
  <slf4j.version>2.0.9</slf4j.version>
</properties>
<dependencyManagement>
...

Links to the referenced pom files for easy access:

I created a minimal example to reproduce this and the steps are almost the same as what I described for this other issue I reported earlier, but I include them below as well.
Similarly to that other issue, I want to point out that since this is the behavior irrespective of whether the parent or child project has a higher version, it is clear that this is NOT an example of the difference in version handling between Coursier and Maven (latest-wins vs nearest-wins), but a separate issue.

Setup: Maven 3.9.0, Coursier 2.1.8
Note: I couldn't figure out how to directly run cs resolve against the local Maven repository, so to serve it on localhost, from ~/.m2/repository run something like npx http-server (or whatever web server you prefer), making it available on http://localhost:8080/

Minimal example: https://github.com/gatisnolv/coursier-issue-2906

Reproduction:
Run mvn install in each of ./parent, ./parent/child directories to install the projects to the Maven local repository.
Observe the difference in result when running inside of the ./parent/child directory mvn dependency:tree against the output of cs resolve -q --cache "./" --repository "http://localhost:8080/" org.fake:child:1.0-SNAPSHOT; rm -rf http*

Note: in the cs resolve command I specify to use as cache the current directory, and do an rm -rf http* after it's done to get updated results in the next run if I change something in the poms (and reinstall them again with mvn install).

@ppkarwasz
Copy link
Author

@gatisnolv, thanks, I corrected my message.

For the examples, it is better to point at the published versions, since those in Git can change:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants