Garret Wilson created MNG-7815:
----------------------------------

             Summary: need for finer-grained base final name property in super 
POM
                 Key: MNG-7815
                 URL: https://issues.apache.org/jira/browse/MNG-7815
             Project: Maven
          Issue Type: Improvement
          Components: POM
            Reporter: Garret Wilson


Maven's [super 
POM|https://maven.apache.org/ref/3.9.2/maven-model-builder/super-pom.html] 
defines {{build.finalName}} like this:

{code:xml}
  <build>
    …
    <finalName>${project.artifactId}-${project.version}</finalName>
{code}

With no changes that produces artifacts like the following for the project 
{{web-app}}:

* {{web-app-1.2.3.jar}}
* {{web-app-1.2.3-javadoc.jar}}
* {{web-app-1.2.3-sources.jar}}

Those defaults are fine used locally, or with the entire 
{{com.example:web-app:1.2.3}} coordinates. But let's say that I'm going to 
upload those JARs somewhere where I want them to have a unique names across 
projects to be stored in the same directory. (AWS Lambda comes to mind.) I want 
to produce artifacts like {{foo-bar-web-app-1.2.3.jar}}. To do that I need to 
override {{build.finalName}} in my POM like this:

{code:xml}
  <build>
    …
    <finalName>foo-bar-${project.artifactId}-${project.version}</finalName>
{code}

I shouldn't need to redefine the entire filename. I'm just wanting to change 
the _base name_—the part that comes before the version. But it gets more 
interesting because I want my Maven build to also produce a Docker image, and I 
need to somehow split out the "base name" and the "version" separately. Using 
{{io.fabric8:docker-maven-plugin}} I'd do something like this:

{code:xml}
<image>
  <name>foo-bar-${project.artifactId}:${project.version}</name>
{code}

I shouldn't have to duplicate the base name.

What I _really_ need is a {{build.finalBaseName}} property. This would be 
extremely simple to add to the Maven super POM in a 100% transparently 
backwards compatible manner. Here is all you need in the super POM:

{code:xml}
  <build>
    …
    <finalBaseName>${project.artifactId}</finalBaseName>
    <finalName>${finalBaseName}-${project.version}</finalName>
{code}

With no changes, all the thousands of Maven POMs work exactly as they did 
before. But if I want to change the base name from {{web-app}} to 
{{foo-bar-web-app}}, I simply do this:

{code:xml}
  <build>
    …
    <finalBaseName>foo-bar-${project.artifactId}</finalBaseName>
{code}

Even better, I don't have to duplicate the base name. Here is what I would use 
to set the Docker image information:

{code:xml}
<image>
  <name>${build.finalBaseName}:${project.version}</name>
{code}

In my own parent POM used across many projects, I'm alrady integrating this 
feature myself as part of 
[JAVA-308|https://globalmentor.atlassian.net/browse/JAVA-308].

{code:xml}
  <properties>
    <build.finalBaseName>${project.artifactId}</build.finalBaseName>

…
  <build>
    <finalName>${build.finalBaseName}-${project.version}</finalName>
{code}

Still it would be very nice to have this fine-grained property available 
automatically with Maven out of the box.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to