Giter VIP home page Giter VIP logo

git-commit-id / git-commit-id-maven-plugin Goto Github PK

View Code? Open in Web Editor NEW
1.6K 41.0 300.0 3.67 MB

Maven plugin which includes build-time git repository information into an POJO / *.properties). Make your apps tell you which version exactly they were built from! Priceless in large distributed deployments... :-)

Home Page: http://www.kto.so

License: GNU Lesser General Public License v3.0

Java 100.00%
maven maven-plugin git build-automation continuous-delivery versioning

git-commit-id-maven-plugin's Introduction

maven git commit id plugin

Build Status Coverage Status Maven Central

git-commit-id-maven-plugin is a plugin quite similar to Build Number Maven Plugin for example but as the Build Number plugin at the time when I started this plugin only supported CVS and SVN, something had to be done. I had to quickly develop a Git version of such a plugin. For those who don't know the plugin, it basically helps you with the following tasks and answers related questions

  • Which version had the bug? Is that deployed already?
  • Make your distributed deployment aware of versions
  • Validate if properties are set as expected

If you are more interested in the different use-cases, feel free to read about them in more detail.

Quicklinks (all relevant documentation)

Getting the plugin

The plugin is available from Maven Central (see here), so you don't have to configure any additional repositories to use this plugin.

A detailed description of using the plugin is available in the Using the plugin document. All you need to do in the basic setup is to include that plugin definition in your pom.xml. For more advanced users we also prepared a guide to provide a brief overview of the more advanced configurations... read on!

Relocation of the Project

Newer version (5.x.x or more recent) are available via

<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>

older version (4.x.x or older) are available via:

<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>

Versions

The current version is 9.0.0 (changelist).

You can check the available versions by visiting search.maven.org, though using the newest is obviously the best choice.

Plugin compatibility with Java

Here is an overview of the current plugin compatibility with Java

Plugin Version Required Java Version
2.1.X Java 1.6
2.2.X Java 1.7
3.X.X Java 1.8
4.X.X Java 1.8
5.X.X Java 11
6.X.X Java 11
7.X.X Java 11
8.X.X Java 11
9.X.X Java 11

Plugin compatibility with Maven

Even though this plugin tries to be compatible with every Maven version there are some known limitations with specific versions. Here is a list that tries to outline the current state of the art:

Plugin Version Minimal Required Maven version
2.1.X Maven 2.2.1 up to v2.1.13; Maven 3.1.1 for any later 2.1.X
2.2.X Maven 3.1.1 up to v2.2.3; Maven 3.0 for any later 2.2.X
3.X.X Maven 3.0
4.X.X Maven 3.0
5.X.X Maven 3.1.0-alpha-1
6.X.X Maven 3.1.0-alpha-1
7.X.X Maven 3.2.5
8.X.X Maven 3.2.5
9.X.X Maven 3.6.3

Flipping the table to maven: Please note that in theory maven 4.X should support all maven 3 plugins. The plugin was first shipped with maven 3 support in version v2.1.14 (requiring maven version 3.1.1). Hence the v2.1.14 should be the first supported version. Only starting with 6.X.X this plugin was acually tested with 4.0.0-alpha-5, but some releases might not work since Maven 4 announced that plugins require Maven 3.2.5 or later which would only be the case for plugin versions 7.0.0 or later.

Maven Version Plugin Version Notes
Maven 3.X any The plugin requires at least a maven 3.1.0-alpha-1
Maven 4.X from v2.1.14

Plugin compatibility with EOL Maven version

End of life (EOL) Maven versions are no longer supported by Maven, nor this plugin. The following information is made available for reference.

Maven Version Plugin Version Notes
Maven 2.0.11 up to 2.2.6 Maven 2 is EOL, git-commit-id-plugin:1.0 doesn't work -- requires maven version 2.2.1
Maven 2.2.1 up to 2.2.6 Maven 2 is EOL
Maven 3.0.X up to 4.0.5 git-commit-id-plugin:2.1.14, 2.1.15, 2.2.0, 2.2.1, 2.2.3 doesn't work -- requires maven version 3.1.1
Maven 3.0.X up to 4.0.5 For git-commit-id-plugin 2.2.4 or higher: works, but failed to load class "org.slf4j.impl.StaticLoggerBinder"
Maven 3.1.0 any git-commit-id-plugin:2.1.14, 2.1.15, 2.2.0, 2.2.1, 2.2.3 doesn't work -- requires maven version 3.1.1
Maven 3.3.1 any git-commit-id-plugin:2.1.14 doesn't work
Maven 3.3.3 any git-commit-id-plugin:2.1.14 doesn't work

Note: As an example -- this table should be read as: For Maven 3.1.0 any Plugin Version should work, besides the ones listed in the Notes have the limitations listed.

Getting SNAPSHOT versions of the plugin

If you really want to use snapshots, here's the repository they are deployed to. But I highly recommend using only stable versions, from Maven Central... :-)

<pluginRepositories>
    <pluginRepository>
        <id>sonatype-snapshots</id>
        <name>Sonatype Snapshots</name>
        <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
    </pluginRepository>
</pluginRepositories>

Older Snapshots (prior version 5.X) are available via <url>https://oss.sonatype.org/content/repositories/snapshots/</url>.

If you just would like to see what the plugin can do, you can clone the repository and run

mvn clean install -Dmaven.test.skip=true && mvn clean package -Pdemo -Dmaven.test.skip=true

Maintainers

This project is currently maintained thanks to: @ktoso (founder), @TheSnoozer

Notable contributions

I'd like to give a big thanks to some of these folks, for their suggestions and / or pull requests that helped make this plugin as popular as it is today:

  • @mostr - for bugfixes and a framework to do integration testing,
  • @fredcooke - for consistent feedback and suggestions,
  • @MrOnion - for a small yet fast bugfix,
  • @cardil and @TheSnoozer - for helping with getting the native git support shipped,
  • all the other contributors (as of writing 50) which can be on the contributors tab - thanks guys,
  • ... many others - thank you for your contributions,
  • ... you! - for using the plugin :-)

Notable happy users

  • neo4j – graph database
  • FoundationdDB – another open source database
  • Spring Boot – yes, the upstream Spring project is using us
  • Akamai, Sabre, EasyDITA, and many many others,
  • many others I don't know of.

License

GNU LGPL v3

I'm releasing this plugin under the GNU Lesser General Public License 3.0.

You're free to use it as you wish, the full license text is attached in the LICENSE file.

Feature requests

The best way to ask for features / improvements is via the Issues section on GitHub - it's better than email because I won't loose when I have a "million emails inbox" day, and maybe someone else has some idea or would like to upvote your issue.

That's all folks! Happy hacking!

git-commit-id-maven-plugin's People

Contributors

abatkin avatar andrebrait avatar autayeu avatar bsodzik avatar cbuschka avatar coladict avatar cousnouf avatar dependabot[bot] avatar frankbregulla1111 avatar fredcooke avatar hazendaz avatar hboutemy avatar hgschmie avatar jonevn avatar joschi avatar katox avatar ktoso avatar maiergre avatar marcono1234 avatar matteobaccan avatar mkordas avatar mkrivan avatar mostr avatar nielsbasjes avatar ryantse avatar secustor avatar sergey-podolsky avatar snago avatar thesnoozer avatar vlatombe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-commit-id-maven-plugin's Issues

Git describe command prefers the newer tag if more than one is on the same hash

And you take the oldest or first. I much prefer the newest one because then I can do something tricky:

Let maven tag as artifact-version during release, release gets build with git describe showing release version, etc. Tag on the same hash after maven is done as the current/next snapshot version, future versions will include the snapshot tag in describe output so as not to confuse users "Yeah, I'm on 0.0.2" when they really mean "I'm on 0.0.3-SNAPSHOT-38commits-some hash".

git-commit-id-plugin seems to hang when called from jenkins (maybe invalid?)

I use git-commit-id-plugin in the validate phase and it seems to run well in my local maven. After I check in my code we have a fusion job that checks out the project and runs a build in it. But the job never seems to end. The job runs a sonar plugin as the final step which in turn calls the cobertura plugin.

It simply hangs at.. (taken from logs)
[INFO] Preparing cobertura:cobertura
[INFO] [git-commit-id:revision {execution: default}]
[info]

The plugin hangs for ever. I configured git-commit-id-plugin to run in validate phase.

Allow initialization once per run (with multiple modules)

buildnumber-maven-plugin has http://mojo.codehaus.org/buildnumber-maven-plugin/create-mojo.html#getRevisionOnlyOnce to fetch the details only once.

With git-commit-id-plugin there is no such open and each module will re-fetch the details.

I tried declaring the plugin on parent POM and setting inherited to false, but then ${git.*} properties don't seem to be available on child modules (even though parent seems to successfully fetch the details).

properties.put() bug

I found a bug in your plugin. Attached file contains source file with bug fix.

This is reproducible when there are no global git config and system git config
on machine where you are running this plugin (in that case NullPointerException
was thrown). It would be great if you commit my fix into new version of your
plugin.

For more details see lines 269-273, there must be following code snippet:

   if (null != value && !"".equals(value.replace(" ", ""))) {
       properties.put(key, value);
   } else {
       properties.put(key, "Unknown");
   }

instead of

   properties.put(key, value);

Best Regards,
Y

Go back to TravisCI

The next release is quite major for the plugin:

  • lots of tests
  • describe implementation
  • bugixes with tests

Let's brag about it and use travis! :)

Add support to execute mojo on pom Projects

Hi,

I've been using your plugin and in one of my projects I've needed to execute on the release steps the following command:

maven clean install assembly:single -N

And some resources that are being filtered have the git properties to be filled. As the top level project is a pom project, the mojo will not execute.

It would be good if you could add a property like:

/**

  • Specified whether the execution in pom projects should be skipped.
  • @parameter expression="${git.skipPoms}" default-value="true"
    */
    private boolean skipPoms;

and then change:

if (isPomProject(project))

to

if (isPomProject(project) && skipPoms)

Thanks,

Commit time bug(s)

Sorry I can't commit code from work, otherwise I would :-(

There seem to be 2 issues.

  1. Commit time should be converted from int to long before conversion to Date (lines 253-256):
  int timeSinceEpoch = headCommit.getCommitTime();
  Date commitDate = new Date(timeSinceEpoch * 1000); // git is "by sec" and java is "by ms"
  SimpleDateFormat smf = new SimpleDateFormat(dateFormat);
  put(properties, prefixDot + COMMIT_TIME, smf.format(commitDate));

Since timeSinceEpoch is something like 1305045215, multiplying by 1000 exceeds MAX_INT and makes it negative. Line 253 should be something like:

long timeSinceEpoch = new Integer(headCommit.getCommitTime()).longValue();
  1. loadBuildTimeData() is overwriting the same property that the above code is setting (lines 191-193):
Date commitDate = new Date();
SimpleDateFormat smf = new SimpleDateFormat(dateFormat);
put(properties, prefixDot + COMMIT_TIME, smf.format(commitDate)); 

Create a new const BUILD_TIME, and use that instead.

The effect of both of these is that ${git.commit.time} actually gives me the build time, which in my case is not the end of the world (it's "close enough"), but it could be very misleading.

Failure on git.properties generation when directory does not exist

I have a parent pom that configures my build for several modules that can be nesting other artifacts.

root pom -> module pom -> several jar pom

If I set up the plugin to run on my root pom, every time it runs in a "pom" packaging artifact, I get a failed build because there is no source folder.

I would suggest that the plugin skips execution when the packaging type of the project is of type "pom"

You can see the stacktrace:

[ERROR] Failed to execute goal pl.project13.maven:git-commit-id-plugin:1.8:revision (default) on project XXX: Could not complete Mojo execution... project_root/src/main/resources/git.properties (No such file or directory) -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal pl.project13.maven:git-commit-id-plugin:1.8:revision (default) on project XXX: Could not complete Mojo execution... at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) Caused by: org.apache.maven.plugin.MojoExecutionException: Could not complete Mojo execution... at pl.project13.maven.git.GitCommitIdMojo.execute(GitCommitIdMojo.java:150) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) ... 19 more Caused by: java.io.FileNotFoundException: project_root/src/main/resources/git.properties (No such file or directory) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(FileOutputStream.java:194) at java.io.FileOutputStream.<init>(FileOutputStream.java:145) at java.io.FileWriter.<init>(FileWriter.java:73) at pl.project13.maven.git.GitCommitIdMojo.generatePropertiesFile(GitCommitIdMojo.java:300) at pl.project13.maven.git.GitCommitIdMojo.execute(GitCommitIdMojo.java:145) ... 21 more

-dirty should only be appended if the user wants that

@eventuallyinconsistent discovered that we're not 1:1 with git's behavior on adding the dirty suffix. Example:

$ git describe --dirty
v2.1.1-1-ge337301-dirty

$ git describe 
v2.1.1-1-ge337301

$ mvn install
[info] Repo is in dirty state = [true] 
[info] [GitCommitIdMojo] Storing: git.commit.id.describe = v2.1.1-1-ge337301-dirty

Document default phase in README.md

Please :-)

And you may want to add a comment about achieving the bean thing by storing the source file out of the usual source tree and filtering it directly into the classes dir using the resources plugin to save the resource loading at runtime stuff, too, though that's up to you.

Default phase on the other hand is somewhat need-to-know ;-)

Add a quiet mode

This plugin is great! So great I want to avoid it having output anything because it just works :) We have a project in which there are many modules built. The git commit id log takes up much of the maven output. For example see http://hudson.opengeo.org/hudson/job/geotools-master/4575/console

So I would like to be able to set an option to prevent most or all of the output. What do you think about a new option named "quiet" that when set would prevent the regular output. Keeping it by default unset of course.

Happy to submit a pull request for this one but just wanted to run the idea by first.

Thanks for the great plugin! It's indispensable for the projects we work on.

<gitDescribe>'s defaults are missing

If the configuration is missing or not all of its options are set, then those options default to null, 0 and similar. In other words, the Maven-style defaults in GitDescribeConfig do nothing. As a result it's necessary to type the full configuration for all of its options.

Infinite loop in 2.1.0 on Mac

Possibly something to do with my file system, and/or the interaction with some library you use, however the build just freezes. top -o cpu shows java taking a core. verbose = true gives 5 lines before the freeze, the last of which is [info]HEAD [hash]. This was working fine, and the config is unchanged, hence file system comment. Still, I'd expect a fail + mesage, not a lock up.

I understand that you're busy, etc. Just noting it here. Will update if I figure anything out.

Could not find dotGitDirectory on multiple plugins

Hi,

We have a big project that has multiple sub projects. i.e.:

  • main
    • module1
      -submodule1
      • project

And the plugin configuration is set on main pom.xml.

If we try to generate a new project from a maven archetype in the submodule1, the error occours.

Do you know how can this be solved?

Also what do you think about -DgitCommit.skip property?

failOnNoGitDirectory property

First of all, great for the plugin, really useful.

We have one case, when "exporting" the git tree using "git archive [branch]" it won't contain the .git directory thus failing when runing the plugin.

A failOnError property with default value to true can help, cause this way if it does not find the .git directory it will still build the project.

Make `git --describe` information available

Hello Konrad,

I currently prefer the simple "git describe --dirty=-DEV --always" for obtaining a version. This way it works with releases and dev versions just the same. Is it possible to get describe-compatible functionality in your plugin?

If not, I can assemble it from the information available to me from your plugin and the META-INF file, with the exception of the dirty state. It'd be nice to have all of that available, though, without excess custom stuff.

Thanks for your time!

Regards,

Fred.

git.branch returning wrong information

I am seeing different results when running under Linux and Windows. When I run the plugin through Windows during development, I get the correct git.branch value:

git.commit.id.abbrev=5a3086c
[email protected]
git.commit.message.full=Branch doesn't seem to be working, so removing the method to get it.\n
git.commit.id=5a3086cfbc994014179d2c573ced4150d143cc0e
git.commit.message.short=Branch doesn't seem to be working, so removing the method to get it.
git.commit.user.name=Chuck May
git.build.user.name=Chuck May
[email protected]
git.branch=master
git.commit.time=27.03.2012 @ 17\:22\:02 EDT
git.build.time=27.03.2012 @ 17\:38\:48 EDT

However when the project is build through continuous integration (Jenkins running under Linux), the git.branch is incorrect:

git.commit.id.abbrev=5a3086c
[email protected]
git.commit.message.full=Branch doesn't seem to be working, so removing the method to get it.\n
git.commit.id=5a3086cfbc994014179d2c573ced4150d143cc0e
git.commit.message.short=Branch doesn't seem to be working, so removing the method to get it.
git.commit.user.name=Chuck May
git.build.user.name=Unknown
git.build.user.email=Unknown
git.branch=5a3086cfbc994014179d2c573ced4150d143cc0e
git.commit.time=27.03.2012 @ 17\:22\:02 EDT
git.build.time=27.03.2012 @ 17\:26\:52 EDT

My pom.xml looks like your sample:

            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>2.0.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <verbose>true</verbose>
                    <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
                    <generateGitPropertiesFilename>src/main/resources/git.properties</generateGitPropertiesFilename>
                </configuration>
            </plugin>

Invalid defaults indicated in docs

Not correct in docs at least for version 2.1.2:

  • abbrev is by default 0 instead of 7
  • verbose is by default false instead of true
  • always is by default false instead of true

Maven 3: Plugin execution not covered by lifecycle configuration

Hi,

Thanks for this great plugin!
I am using it with Maven 3, configured as follows:

        <plugin>
            <groupId>pl.project13.maven</groupId>
            <artifactId>git-commit-id-plugin</artifactId>
            <version>1.9</version>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>revision</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <dateFormat>yyyy-MM-dd</dateFormat>
                <verbose>false</verbose>
                <generateGitPropertiesFile>false</generateGitPropertiesFile>
            </configuration>
        </plugin>

However, Eclipse does not like it and reports an error at the <execution> line:

Plugin execution not covered by lifecycle configuration: pl.project13.maven:git-commit-id-plugin:1.9:revision (execution: default, phase: initialize)

On Mac OS X it works regardless, but on Windows the error results in a build failure.

I have experimented a bit to see if other phases would work. It turns out that of the default Maven lifecycle only the following are accepted by Eclipse:

  • test
  • package
  • verify
  • install
  • deploy

Sadly, all of these phases are too late to make use of the properties.

Is there a way to get Maven 3 to run the plugin before the process-resources phase ("initialize" would be ideal)?

Reveal describe details (tag name, number of commits, commit id) in their own properties

With describe returning something like 1.0.0-13-abc1234, we want each part in their separate property so we can build finalName with custom scheme.

Commit id is already put into separate field. Support would be needed for:

  • Tag name
  • Number of commits since last tag

Maybe as git.closest.tag.name and git.closest.tag.commit.count or something like that?

.properties files escape date formatters like :

I've noticed that date formatter like "dd.MM.yyyy @ HH:mm:ss z" produce \ escaped : in the .properties file

git.commit.time=27.08.2013 @ 16\\:59\\:19 CEST
git.build.time=22.10.2013 @ 12\\:31\\:41 CEST

Also some \n chars is escaped:

git.commit.message.full=Updated maven repo infos\n

.git file refers to .git directory for submodule

I suddenly got the following error message in maven:

[ERROR] Failed to execute goal pl.project13.maven:git-commit-id-plugin:1.9:revision (default) on project utils: Could not get HEAD Ref, are you sure you've set the dotGitDirectory property of this plugin to a valid path? -> [Help 1]

I didn't move the .git directory or changed the module's configuration but a look at the .git directory revealed that it now is a file with the following content:

gitdir: /path-to-my-home/repos/myproject/.git/modules/utils

whereas the project I was building is a git submodule located in /path-to-my-home/repos/myproject/utils. The parent project/module is located in /path-to-my-home/repos/myproject.

I'm using version 1.9 of the maven-git-commit-id-plugin, git version 1.7.8 and Apache Maven 3.0.3

GIT_DIR and GIT_WORK_TREE not respected

git dir to find the git dir (allow it to override the usual find mechanism and/or variable), and the work dir for git status/describe checking. Thanks in advance :-)

Describe does not match command line

Running on Win7, the describe command is missing both the number of commits since tag, and the commit hash.

$ git describe --always --dirty=-uncommitted
sample-service-1.0.0-6-g1a28bee-uncommitted

$ cat src/main/resources/git.properties
git.commit.id.describe=sample-service-1.0.0-uncommitted

Feature request: git repo information

Great plugin! Would be even better if I could see some of the information from git remote -v show, specifically the URL and remote name. That way I could see if a build was deployed from a Github fork or from the main repo.

The plugin fails when it can't find a revision

The plugin fails when it can't find a revision. I think it happend because someone amended a commit. It could also be because travis doesn't fetch all revisions.

You can reproduce the problem like this:

git clone --depth=100 --quiet --branch=branchname git://github.com/crawljax/crawljax.git
cd crawljax
git checkout -qf 8c2e0f52d27c33df5e1c4c2deec472b1e138d67a
mvn clean package -DskipTests=true

This results in the error:

[ERROR] Failed to execute goal pl.project13.maven:git-commit-id-plugin:2.1.4:revision (default) on project crawljax-core: Execution default of goal pl.project13.maven:git-commit-id-plugin:2.1.4:revision failed: Unable to calculate distance between [commit 8c2e0f52d27c33df5e1c4c2deec472b1e138d67a 1359301377 ----sp] and [commit c8c9b49da0750d39f51b282e29f70672fb657b65 1356953576 ----sp]: Missing commit a19d505b92d4e73d39ab554cff26dc59dc8e25a9 -> [Help 1]

Here's an example of a failed build

I don't mind that it doesn't work, but it shouldn't break the build IMHO.

Release 1.5+

would you mind releasing a 1.6 version to oss?

NullPointerException when git repo is brand new (no commits)

[ERROR] Failed to execute goal pl.project13.maven:git-commit-id-plugin:2.1.2:revision (default) on project abc: Execution default of goal pl.project13.maven:git-commit-id-plugin:2.1.2:revision failed. NullPointerException -> [Help 1]

This is on 2.1.2, 2.1.3 didn't make it to me yet. Maybe you don't care. Pretty obscure use-case :-) Feel free to close wont-fix if you like. Just wanted to document it.

Describe --dirty marks dirty when it's not.

Found in 2.1.0-2.1.2

If a file is tracked, and changed, but not committed, the repo is considered dirty.
If a file is not tracked it is simply not tracked and not part of the repo at all.

Starting with a pristine git directory with the following (dangerous) commands:

git reset --hard TAG
git clean -dfx

git describe --dirty=-DEV

should return TAG

touch afile

should still return TAG because afile is not tracked, just extra.

echo "png" >> .gitignore # assuming we had that tracked

should now return TAG-DEV because .gitignore has now been modified and not committed.

Just in case it matters: I noticed this due to a new package with some source files inside it. IE an untracked directory within a tracked directory. (yes I know git doesn't care about dirs)

I hope that helps :-)

Could not find .git directory with findbugs

(using maven 2.2.1 on linux, with maven-git-commit-id-plugin 2.0.1)

Hi,

I'm using the findbugs plugin to analyse my code and when I run a

  • mvn clean install checkstyle:checkstyle findbugs:findbugs

I get the following error:

[INFO] [checkstyle:checkstyle {execution: default-cli}]
[WARNING] Unable to locate Source XRef to link to - DISABLED
[INFO] Preparing findbugs:findbugs
[INFO] [git-commit-id:revision {execution: default}]
******************************************* false
------------------------------------------- /tmp/root/libs/lib1/.git
=========================================== /tmp/root/libs/lib1
******************************************* null
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Could not find .git directory. Please specify a valid dotGitDirectory in your pom.xml
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Could not find .git directory. Please specify a valid dotGitDirectory in your pom.xml
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkProjectLifecycle(DefaultLifecycleExecutor.java:1205)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkLifecycle(DefaultLifecycleExecutor.java:1038)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:643)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Could not find .git directory. Please specify a valid dotGitDirectory in your pom.xml
at pl.project13.maven.git.GitCommitIdMojo.lookupGitDirectory(GitCommitIdMojo.java:202)
at pl.project13.maven.git.GitCommitIdMojo.execute(GitCommitIdMojo.java:137)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 21 more

My structure is:

  • root (where I define the use of maven-git-commit-id-plugin)
    • libs
      • lib1
      • lib2

On lib1 and lib2 I get this error.

Meanwhile I've got the code and tried with v 2.0.1 and put some prints on the code:

    dotGitDirectory = new File(mavenProject.getBasedir(), Constants.DOT_GIT);

System.out.println("* "+mavenProject.hasParent());
System.out.println("------------------------------------------- "+dotGitDirectory.toString());
System.out.println("=========================================== "+mavenProject.getBasedir().toString());
System.out.println("
* "+mavenProject.getParent());
if (dotGitDirectory.exists() && dotGitDirectory.isDirectory()) {

And on the first and last prints I get false and null when running under lib1 and lib2.

All the poms are linked to the parents and in the install goal the plugin runs just fine...

Unknown repository format "null"? (JGit issue?)

Issue reported via twitter, see bellow:

@gridinoc: @ktosopl Unknown repository format "null" git-commit-id-plugin :( http://gist.github.com/1110528 any clue?
@ktosopl: @gridinoc it's possible that it fails to understand "../". Try to ommit dotGitDirectory configuration, it will try to find it automagically
@gridinoc: @ktosopl found it automatically, same error, odd.
@ktosopl: @gridinoc does this repository have commits already? That is have you done any "git commit"? If you did only "git init" it may fail hmm
@gridinoc: @ktosopl here's the stack trace https://gist.github.com/1110528#comments
@gridinoc: @ktosopl it has commits and is also in sync with a private github one

I'm on it Laurian!
Thanks a lot for using my plugin :-)

Git Commit messages with '%' can cause plugin failure

I had a git commit message as follows:

'- Finished tests for User Account service and Network service (100% coverage)'

The plugin failed with an error about logging. See stack trace:

[info] [GitCommitIdMojo] Storing: git.commit.user.email = REDACTED
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Conversion = c, Flags =  
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.util.FormatFlagsConversionMismatchException: Conversion = c, Flags =  
    at java.util.Formatter$FormatSpecifier.failMismatch(Formatter.java:4041)
    at java.util.Formatter$FormatSpecifier.checkBadFlags(Formatter.java:2949)
    at java.util.Formatter$FormatSpecifier.checkCharacter(Formatter.java:2926)
    at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2682)
    at java.util.Formatter.parse(Formatter.java:2528)
    at java.util.Formatter.format(Formatter.java:2469)
    at java.util.Formatter.format(Formatter.java:2423)
    at java.lang.String.format(String.java:2845)
    at pl.project13.maven.git.log.MavenLoggerBridge.log(MavenLoggerBridge.java:35)
    at pl.project13.maven.git.GitCommitIdMojo.log(GitCommitIdMojo.java:496)
    at pl.project13.maven.git.GitCommitIdMojo.putWithoutPrefix(GitCommitIdMojo.java:481)
    at pl.project13.maven.git.GitCommitIdMojo.put(GitCommitIdMojo.java:475)
    at pl.project13.maven.git.GitCommitIdMojo.loadGitData(GitCommitIdMojo.java:379)
    at pl.project13.maven.git.GitCommitIdMojo.execute(GitCommitIdMojo.java:239)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

Looks like it should be a simple character escape on the git message?

@threadSafe annotation

We parallels builds a lot where i work, and many plugins still get a warning like below.

If this plugin is thread safe, can you please specify it as such ?

See specification here http://maven.apache.org/developers/mojo-api-specification.html

Warning from maven below.

[WARNING] *****************************************************************
[WARNING] * Your build is requesting parallel execution, but project      *
[WARNING] * contains the following plugin(s) that are not marked as       *
[WARNING] * @threadSafe to support parallel building.                     *
[WARNING] * While this /may/ work fine, please look for plugin updates    *
[WARNING] * and/or request plugins be made thread-safe.                   *
[WARNING] * If reporting an issue, report it against the plugin in        *
[WARNING] * question, not against maven-core                              *
[WARNING] *****************************************************************
[WARNING] The following plugins are not marked @threadSafe in <Projectname>
[WARNING] pl.project13.maven:git-commit-id-plugin:2.1.4
[WARNING] *****************************************************************

To reproduce: create a multi module project, and requst parallel execution by using the following command.

mvn -T 1.5C clean deploy

multi-module config with pluginManagement

Somewhere between 2.1.4 and now the behavior of the plugin has changed with regard to multi-module configuration.

Specifically, if the git-commit-id-plugin is configured in a section of a parent POM, the value of is now expanded with respect to the parent pom.

So even though the plugin may run multiple times in multiple maven submodules, it will overwrite the same file repeatedly.

In 2.1.4, the behavior was different. If was set to resources/git.properties in the parent pom, then it would be generated for each maven module:

submodule1/resources/git.properties
submodule2/resources/git.properties

Allow to limit git properties exposed

The plugin discloses too many properties, which may be undesirable when e.g. generated jar package is distributed. It should be possible to prevent some properties from being inserted into git.properties file, mainly:
git.commit.message.full, git.commit.message.short
git.commit.user.email, git.build.user.email
git.commit.user.name, git.build.user.name
git.remote.origin.url <- especially this one, it may even contain repo password!

Generally all properties possibly containing private sensitive information should be possible to ommit. In my case, git.commit.id.describe is the only property I need.

Self reference makes initial install problematic

Requested by an user via email.
Yes, the self reference may indeed cause some problems - I have removed it and installing should now work fine.
It's included in 1.5 (sight... should have naed it like 1.4.1 or something better than a 1.x release by the way...)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.