Closed wtmtgmgxj closed 5 years ago
Hi, thanks for reporting your issue. I believe this is a known issue outlined in the FAQ section (https://github.com/git-commit-id/maven-git-commit-id-plugin/blob/master/docs/faq.md#generated-properties-are-not-being-used-in-install-andor-deploy)
I'd refer to the full workaround linked in the docs.
Sadly there is nothing we could do differently on our side, since it's simply not intended by the maven eco system to have dynamic version numbers (hence the plugins need to be used with the workaround suggested).
I read and implemented the full workaround, however I was stuck in one case. I have a parent module which is pom packaging, whereas the subModules are jar packaging.
I have included the Maven Install Plugins and Maven Jar Plugins in all of my subModules, and they are working fine, installing jars with correct name. However when I run mvn clean install on the parent module, I get the following error.
[ERROR] 'dependencies.dependency.version' for com.submodule:jar must be a valid version but is '${git.branch}'.
Do you have any hints on why this configuration is not working when building the parent pom
Sadly, I need to say: welcome to the pain of maven. The maven eco-system is essentially not designed to have version to be dynamic and I don't see anything we can do about it.
In your situation I'd also refer to https://github.com/git-commit-id/maven-git-commit-id-plugin/issues/377#issuecomment-413723156 that might help to fix your problem.
Maybe overall alternative solutions like generating the pom on the fly with https://www.mojohaus.org/flatten-maven-plugin/usage.html might be an interesting alternative. I'd guess there might be other plugins available to generate the pom with a dynamic version on the fly. So I'm thinking here in a direction where maven just sees a pom with a fixed version.
All together, I'd say dynamic versions are not really supported and hence I can't do anything besides referring to lengthy workarounds. Trust me, this pain was one of the reasons why I stopped using maven.
Hope this helps anyways.
Hello @TheSnoozer . I have implemented the plugin, but git.branch returns the appropriate value(actual branch) for some projects, but it returns git.commit.id instead of the branch for some others. I did exactly the same on all maven projects..
Hi, thanks for the follow up.
Usually the branch can become the 'commit id' when the current repo is in a 'detached head' state. In such state the branch is not known from the perspective of git. CI Tools like Jenkins/Hudson/Travis will usually perform builds in a 'detached head' state, however in most cases they are configured to perform tests on a specific branch. To help to resole the 'right' branch anyways they also export the current branch as environment variable for the current build.
If you run this plugin in a CI environment, this plugin will check if a 'branch' environment variable is present. If not will attempt to resolve the branch with the power of git. If all of this does not lead to a specific branch, this plugin will return the commit-id instead (so from my perspective this is expected and documented behavior).
I don't know much about your current build procedure, but I'd suspect that the builds where git.branch
will become git.commit.id
are the builds where your repo is a detached head.
From the plugin side I'd refer to https://github.com/git-commit-id/maven-git-commit-id-plugin/blob/master/docs/using-the-plugin.md#generated-properties
For more general info's on the 'git behaviour' I'd refer to https://git-scm.com/docs/git-checkout#_detached_head
Hi, I hopefully provided sufficient context why this is just a hell with maven and since this now seem to have gotten stale I think I can go ahead and close this specific issue. If there is any more feedback, please feel free to share it, since it might help someone else who bumps into the same issue.
I have included the plugin as shown , but its not working. Please note that I need Git Branch in Version Tag.
Expected behavior
Here's My Console on running "maven clean install"
Please see the last line of the output, I was expecting ${git.branch} to be replaced by real branch name
Other configs-- Maven home: /usr/local/Cellar/maven/3.6.0/libexec Java version: 1.8.0_192, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/jre Default locale: en_IN, platform encoding: UTF-8 OS name: "mac os x", version: "10.13.6", arch: "x86_64", family: "mac"