3

I try to include the git commit hash in the artifact name to distinguish between Snapshot-Versions in an CI scenario. The git hash is successfully included in the target/ folder of my project, but in the last maven step it copies the artifact into my HOME/.m2/repositories folder and changes the name to ARTIFACTID-VERSION-mta.jar.

How can I keep the file name from the target/ folder that includes the commit hash?

I had a look at the maven-install-plugin, but couldn't find a "finalName" property or something like this.

[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ projectname ---
[INFO] Installing PROJECTDIR/pom.xml to ~/.m2/repository/GroupIdDir/projectname/1.0.1/projectname-1.0.1.pom
[INFO] Installing PROJECTDIR/target/projectname-1.0.1-d054c42-mta.jar to ~/.m2/repository/GroupIdDir/projectname/1.0.1/projectname-1.0.1-mta.jar

I would like the last line to be

[INFO] Installing PROJECTDIR/target/projectname-1.0.1-d054c42-mta.jar to ~/.m2/repository/GroupIdDir/projectname/1.0.1/projectname-1.0.1-d054c42-mta.jar

Controlling maven final name of jar artifact does not solve the problem because it modifies the output folder.

Community
  • 1
  • 1
Steffen Schmitz
  • 860
  • 3
  • 16
  • 34
  • You can't do that. The name in the local repository follows the `artifacId-version(-classifier).type` convention, and you cannot change it. See http://stackoverflow.com/questions/17024803/version-in-jar-name – Tunaki Nov 17 '16 at 12:35
  • Can I set the commit hash as a classifier? – Steffen Schmitz Nov 17 '16 at 12:37
  • You _could_ but that does mean its Maven coordinates will change each time there's a new commit, so each project depending on it will need to change the `` declaration _for each commit_. See http://stackoverflow.com/questions/8354201/how-do-i-build-only-one-jar-file-with-classifier for that. It sounds like you're trying to rebuild the SNAPSHOT mechanism of Maven from scratch. Why not version your project `1.0.1-SNAPSHOT`? – Tunaki Nov 17 '16 at 12:40
  • I want to know which commit led to a snapshot-version or release-version of an artifact once it is deployed somewhere else. If there is a bug it should be easy to get to the relevant commit from the deployed artifact. – Steffen Schmitz Nov 17 '16 at 12:43
  • 1
    Then don't add this information in the name of the file. For this usecase, this is typically added in the Manifest on another file. See https://github.com/ktoso/maven-git-commit-id-plugin for Git or http://stackoverflow.com/questions/31510244/how-to-add-svn-revision-number-to-manifest-file – Tunaki Nov 17 '16 at 12:48

1 Answers1

0

it is probrably because of repository layout.

Repository Layout Definition

This is the final layout for the repository available in Maven 2.x and its related Ant tasks.

For primary artifacts: /$groupId[0]/../${groupId[n]/$artifactId/$version/$artifactId-$version.$extension

For secondary artifacts: /$groupId[0]/../$groupId[n]/$artifactId/$version/$artifactId-$version-$classifier.$extension

See https://cwiki.apache.org/confluence/display/MAVENOLD/Repository+Layout+-+Final

Community
  • 1
  • 1
Vagner Nogueira
  • 131
  • 2
  • 5
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes – Jeff Richards Nov 12 '17 at 00:54