flatten-maven-plugin icon indicating copy to clipboard operation
flatten-maven-plugin copied to clipboard

Not able to produce a BOM with ${revision} resolved for dependencies

Open gurgl opened this issue 6 years ago • 6 comments

I have a project like this:

myproject-parent

  • myproject-bom
  • myproject-artifact1
  • myproject-artifact2 ...

Wo using ${revisiion} it quite simple. I use ${project.version} to address inter module dependencies and in the BOM i use resolved versions (AS YOU CANNOT USE project.version when inheriting a bom for coordinates) outside the project. The artifacts in the project also inherit the BOM.

Following this guide maven-ci-friendly I cannot create a working BOM that has resolved ${revision} for PROJECT dependencies. The BOM version has ${revision} replace but not the dependencies listed in it. When using flattenMode =resolveCIFriendlyOnly i get the following bom produced:

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.myproject</groupId>
    <artifactId>myproject-parent</artifactId>
    <version>16.0.0-651-SNAPSHOT</version>
  </parent>
  <groupId>com.myproject</groupId>
  <artifactId>myproject-bom</artifactId>
  <version>16.0.0-651-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>myproject-bom</name>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.myprojectr</groupId>
        <artifactId>myproject-artifact1</artifactId>
        <version>${revision}</version>
      </dependency>
      <dependency>

...this works as long as the project inheriting this bom dont rely on ${revision}. I know the above linked guide mentions you shouldnt use ${revision} for project artifact coordinates - but project.version is useless for a BOM made for inheritance. There should be flattenMode that replaces ${revision} throughout.

gurgl avatar Aug 30 '19 00:08 gurgl

Ie for revision=1.2.3-FEATURE-456-SNAPSHOT. The BOM i want my project to produce should look like this (with resolved project dependency versions) :

      <dependency>
        <groupId>com.myprojectr</groupId>
        <artifactId>myproject-artifact1</artifactId>
        <version>1.2.3-FEATURE-456-SNAPSHOT</version>
      </dependency>
      ...

gurgl avatar Sep 02 '19 12:09 gurgl

i have the same problem, Have you solved the problem?

hupuxiaojun avatar Nov 02 '19 07:11 hupuxiaojun

Sorry for late answer. Nope. Havent solved this. Makes $[revision] + flatten sort of useless.

gurgl avatar Nov 13 '19 08:11 gurgl

i'm having the same problem i created a little reproducer: https://github.com/a1dutch/flatten-revision

this is the output of the flatterned pom using resolveCiFriendliesOnly flatten mode

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>uk.co.a1dutch</groupId>
    <artifactId>flatten-revision-build</artifactId>
    <version>0.9.1-SNAPSHOT</version>
  </parent>
  <groupId>uk.co.a1dutch</groupId>
  <artifactId>flatten-revision-dependencies</artifactId>
  <version>0.9.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <properties>
    <should-be-flattened>${revision}</should-be-flattened>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>uk.co.a1dutch</groupId>
        <artifactId>flatten-revision-dependent</artifactId>
        <version>${revision}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

its not swapping out dependency management or properties

a1dutch avatar May 06 '21 09:05 a1dutch

We've able to solve this by replacing both this maven-flatten-plugin and the release plugin we used.

  1. ci-friendly flatten plugin https://medium.com/outbrain-engineering/faster-release-with-maven-ci-friendly-versions-and-a-customised-flatten-plugin-fe53f0fcc0df

  2. (optional maybe) https://github.com/aleksandr-m/gitflow-maven-plugin

Its been working absolutely great on multiple projects.

gurgl avatar May 07 '21 01:05 gurgl

just user this:

mvn clean deploy -Drevision=1.2.3-FEATURE-456-SNAPSHOT

CraKeyBoy avatar Aug 06 '21 12:08 CraKeyBoy