Giter VIP home page Giter VIP logo

gradle-git-properties's Introduction

about

This Gradle plugin can be used for generating git.properties file generation for Git-based projects (similar to maven git commit id plugin). It can be used for (but not limited to) Spring Boot apps. Plugin is available from Gradle Plugins repository.

Idea - @lievendoclo, originally published in article Spring Boot's info endpoint, Git and Gradle - InsaneProgramming.

Build Status

compatibility matrix

This Gradle plugin is compatible with the following versions of Gradle:

Plugin version Min. Gradle version
2.3.2 5.1
2.2.4 4.x

notes

  • Plugin requires Java 8+
  • If git.properties is missing on Gradle 5.1.x and 5.2.x Issue 128, use gitPropertiesResourceDir to config a different output directory
  • Since gradle-git-properties v2.x, we require JGit 5.x, this might cause some issues if you have other gradle plugin which uses JGit 1.4.x. In that case, you can use gradle-git-properties v1.5.x (instead of 2.x) which uses JGit 1.4.x. See Issue 133 for more info about this plugin's dependencies
  • With gradle-git-properties v2.2.4, v2.3.0, and v2.3.1, grgit v4.1.0 always requires the latest JGit which can be 6+, this cause build fails if you run Gradle with Java under 11. See Issue 195 for more info about this issue

usage

Declare this in your build.gradle

plugins {
  id "com.gorylenko.gradle-git-properties" version "2.4.2"
}

A git.properties file will be generated when building Java-based projects (the plugin will configure any existing classes task to depend on generateGitProperties task - which is responsible for generated git.properties file). For non-Java projects, generateGitProperties task must be executed explicitly to generate git.properties file. The git repository for the project will be used.

Spring Boot specific info: This is enough to see git details via info endpoint of spring-boot-actuator.

If needed - override folder and file name of the generated file using gitPropertiesName and gitPropertiesResourceDir config keys. (NOTE: By default, the file will be generated at build/resources/main/git.properties)

gitProperties {
    // Customize file name (could be a file name or a relative file path below gitPropertiesResourceDir dir)
    gitPropertiesName = "my-git-file.properties"

    // Customize directory using gitPropertiesResourceDir config
    // The directory in this config key is also added as a classpath entry
    // (so the git.properties file will be included in the final JAR file)
    gitPropertiesResourceDir = "${project.rootDir}/my/generated-resources-dir"

    // (Deprecated, for compatibility only)
    // Customize directory using gitPropertiesDir config
    gitPropertiesDir = "${project.rootDir}/your/custom/dir"
}

Please note that spring-boot-actuator expects git.properties to be available at certain location.

If needed - use dateFormat and dateFormatTimeZone to format git.commit.time property (See SimpleDateFormat and TimeZone for valid values)

gitProperties {
    dateFormat = "yyyy-MM-dd'T'HH:mmZ"
    dateFormatTimeZone = "PST"
}

Note: Kotlin DSL syntax

configure<com.gorylenko.GitPropertiesPluginExtension> { dateFormat = "yyyy-MM-dd'T'HH:mmZ" }

If needed - use branch to override git branch name (when it cannot be detected correctly from environment variables/working directory)

gitProperties {
    branch = System.getenv('GIT_BRANCH')
}

By default, all git properties which are supported by the plugin will be generated:

git.branch
git.build.host
git.build.user.email
git.build.user.name
git.build.version
git.closest.tag.commit.count
git.closest.tag.name
git.commit.id
git.commit.id.abbrev
git.commit.id.describe
git.commit.message.full
git.commit.message.short
git.commit.time
git.commit.user.email
git.commit.user.name
git.dirty
git.remote.origin.url
git.tags
git.total.commit.count

You can have more fine-grained control of the content of git.properties using keys:

gitProperties {
    keys = ['git.branch','git.commit.id','git.commit.time']
}

Custom properties can be added with customProperty (supports both expressions and closures):

gitProperties {
    customProperty 'greeting', 'Hello' // expression
    customProperty 'my_custom_git_id', { it.head().id } // closure, 'it' is an instance of org.ajoberstar.grgit.Grgit
    customProperty 'project_version', { project.version } // closure
}

You can also replace standard properties using customProperty. In the below example, the logic it.describe(tags: true) will replace the plugin's logic which using describe(tags: false)

gitProperties {
    // using any tags (not limited to annotated tags) for "git.commit.id.describe" property
    // see http://ajoberstar.org/grgit/grgit-describe.html for more info about the describe method and available parameters
    // 'it' is an instance of org.ajoberstar.grgit.Grgit
    customProperty 'git.commit.id.describe', { it.describe(tags: true) } 
}

Spring Boot specific info: By default, the info endpoint exposes only git.branch, git.commit.id, and git.commit.time properties (even then there are more in your git.properties). In order to expose all available properties, set the "management.info.git.mode" property to "full" per the Spring Boot documentation, e.g. in application.properties:

management.info.git.mode=full

The .git directory for the project should be detected automatically, otherwise it can be specified manually using dotGitDirectory:

gitProperties {
    dotGitDirectory = "${project.rootDir}/../somefolder/.git"
}

Note: Kotlin DSL syntax

configure<com.gorylenko.GitPropertiesPluginExtension> {
    (dotGitDirectory as DirectoryProperty).set("${project.rootDir}/../somefolder/.git")
}

If for some reason, the .git directory for the project doesn't exist and you don't want the task to fail in that case, use failOnNoGitDirectory=false:

gitProperties {
    failOnNoGitDirectory = false
}

To skip plugin execution completely, configure the enabled property:

tasks.withType(com.gorylenko.GenerateGitPropertiesTask).all { enabled = false }

result from info endpoint (if used with Spring Boot apps)

When using with Spring Boot: This is raw JSON from info endpoint (with management.info.git.mode=simple or not configured):

{
  "git": {
    "commit": {
      "time": "2018-03-28T05:13:53Z",
      "id": "32ff212"
    },
    "branch": "Fix_issue_68"
  }
}

This is raw JSON from info endpoint (with management.info.git.mode=full):

{
  "git": {
    "build": {
      "host": "myserver-1",
      "version": "0.0.1-SNAPSHOT",
      "user": {
        "name": "First Last",
        "email": "[email protected]"
      }
    },
    "branch": "Fix_issue_68",
    "commit": {
      "message": {
        "short": "Fix issue #68",
        "full": "Fix issue #68"
      },
      "id": {
        "describe": "v1.4.21-28-g32ff212-dirty",
        "abbrev": "32ff212",
        "full": "32ff212b9e2873fa4672f1b5dd41f67aca6e0731"
      },
      "time": "2018-03-28T05:13:53Z",
      "user": {
        "email": "[email protected]",
        "name": "First Last"
      }
    },
    "closest": {
      "tag": {
        "name": "v1.4.21",
        "commit": {
          "count": "28"
        }
      }
    },
    "dirty": "true",
    "remote": {
      "origin": {
        "url": "[email protected]:n0mer/gradle-git-properties.git"
      }
    },
    "tags": "",
    "total": {
      "commit": {
        "count": "93"
      }
    }
  }
}

other usages

This plugin can also be used for other purposes (by configuring extProperty to keep generated properties and accessing the properties from project.ext).

Note that the git.properties file is always generated and currently there is no option to disable it. Please also make sure that the generateGitProperties task is executed before accessing the generated properties.

In the below example, printGitProperties will print git.commit.id.abbrev property when it is executed:

gitProperties {
    extProperty = 'gitProps' // git properties will be put in a map at project.ext.gitProps
}
generateGitProperties.outputs.upToDateWhen { false } // make sure the generateGitProperties task always executes (even when git.properties is not changed)

task printGitProperties(dependsOn: 'generateGitProperties') { // make sure generateGitProperties task to execute before accessing generated properties
    doLast {
        println "git.commit.id.abbrev=" + project.ext.gitProps['git.commit.id.abbrev']
    }
}

Below is another example about using generated properties for MANIFEST.MF of a Spring Boot webapp (similar can be done for non Spring apps). Note the usage of GString lazy evaluation to delay evaluating project.ext.gitProps['git.commit.id.abbrev'] until MANIFEST.MF is created. Because generateGitProperties task will always execute automatically before any classes task (in Java projects), no dependsOn is needed for bootJar task.

gitProperties {
    extProperty = 'gitProps' // git properties will be put in a map at project.ext.gitProps
}
generateGitProperties.outputs.upToDateWhen { false } // make sure the generateGitProperties task always executes (even when git.properties is not changed)

bootJar {
  manifest {
    attributes(
        'Build-Revision': "${-> project.ext.gitProps['git.commit.id.abbrev']}"  // Use GString lazy evaluation to delay until git properties are populated
    )
  }
}

Note: Kotlin DSL syntax (similar to above GString example)

// [...]
put("Implementation-Version", object {
  override fun toString():String = (project.extra["gitProps"] as Map<String, String>)["git.commit.id"]!!
})
// [...]

more notes

If you need to use a specific JGit version (e.g. because of version conflict), check the below example:

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath ("com.gorylenko.gradle-git-properties:gradle-git-properties:2.4.2") {
        exclude group: 'org.eclipse.jgit', module: 'org.eclipse.jgit' // remove plugin's jgit dependency
    }
    classpath 'org.eclipse.jgit:org.eclipse.jgit:5.5.0.201909110433-r' // use the specified jgit dependency
  }
}

apply plugin: "com.gorylenko.gradle-git-properties"

apply plugin: 'java'

license

gradle-git-properties is Open Source software released under the Apache 2.0 license

gradle-git-properties's People

Contributors

aalmiray avatar behrangsa avatar bfg avatar bgorven avatar davinkevin avatar edwardprentice avatar endron avatar izeye avatar joschi avatar ka1eka avatar kennysoft avatar keteh avatar kkocel avatar lynxplay avatar marcus-bcl avatar martinreck avatar n0mer avatar nathansgreen avatar piotrturski avatar shalugin avatar tha2015 avatar tryptophane 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

gradle-git-properties's Issues

License issue - Some logic is modified from LGP code (maven-git-commit-id-plugin)

Some of the recent commits used modified logic from maven-git-commit-id-plugin which is under LGPL 3.0 license. The reason for it is to keep compatibility between two plugins.

The problem is Gradle plugin is under Apache license while maven-git-commit-id-plugin is under LGP 3 license which is not compatible.
So we should either replace recent commits which using modified logic from maven-git-commit-id-plugin by clean-room implementation or change the license to LGPL 3 license.

The impacted files are:
src\main\groovy\com\gorylenko\GitDirLocator.groovy (searching for dotGitDirectory)
src\main\groovy\com\gorylenko\RemoteOriginUrlProperty.groovy (git.remote.origin.url property)

@n0mer What do you think about this?

v1.4.21 Regression: Can no longer use org.ajoberstar.grgit directly.

Using Gradle v4.6 this build script

plugins {
    id 'java'
    id "org.ajoberstar.grgit" version "2.1.1"
}

and this build script

plugins {
    id 'java'
    id "com.gorylenko.gradle-git-properties" version "1.4.21"
}

both work.

But when you combine the two, such as with this one

plugins {
    id 'java'
    id "org.ajoberstar.grgit" version "2.1.1"
    id "com.gorylenko.gradle-git-properties" version "1.4.21"
}

it fails with this error

$  ./gradlew clean assemble --stacktrace                                                                                                                                                  

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/me/sample/build.gradle' line: 3

* What went wrong:
An exception occurred applying plugin request [id: 'org.ajoberstar.grgit', version: '2.1.1']
> Failed to apply plugin [id 'org.ajoberstar.grgit']
   > Could not create plugin of type 'GrgitPlugin'.
      > org/ajoberstar/grgit/exception/GrgitException

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'org.ajoberstar.grgit', version: '2.1.1']
        at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.exceptionOccurred(DefaultPluginRequestApplicator.java:247)
        at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:229)
        at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:148)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:184)
        at org.gradle.configuration.BuildOperationScriptPlugin$1.run(BuildOperationScriptPlugin.java:61)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.configuration.BuildOperationScriptPlugin.apply(BuildOperationScriptPlugin.java:58)
        at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:41)
        at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
        at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:64)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.access$100(LifecycleProjectEvaluator.java:34)
        at org.gradle.configuration.project.LifecycleProjectEvaluator$ConfigureProject.run(LifecycleProjectEvaluator.java:110)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:50)
        at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:667)
        at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:136)
        at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:35)
        at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:60)
        at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
        at org.gradle.initialization.DefaultGradleLauncher$ConfigureBuild.run(DefaultGradleLauncher.java:261)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.initialization.DefaultGradleLauncher.configureBuild(DefaultGradleLauncher.java:173)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:132)
        at org.gradle.initialization.DefaultGradleLauncher.executeTasks(DefaultGradleLauncher.java:115)
        at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:78)
        at org.gradle.internal.invocation.GradleBuildController$1.call(GradleBuildController.java:75)
        at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:152)
        at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:100)
        at org.gradle.internal.invocation.GradleBuildController.run(GradleBuildController.java:75)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
        at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$1.run(RunAsBuildOperationBuildActionRunner.java:43)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40)
        at org.gradle.tooling.internal.provider.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:51)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:49)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:32)
        at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:39)
        at org.gradle.launcher.exec.BuildTreeScopeBuildActionExecuter.execute(BuildTreeScopeBuildActionExecuter.java:25)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:80)
        at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:53)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:57)
        at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:32)
        at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
        at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
        at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:43)
        at org.gradle.tooling.internal.provider.ParallelismConfigurationBuildActionExecuter.execute(ParallelismConfigurationBuildActionExecuter.java:29)
        at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:64)
        at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:29)
        at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:59)
        at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:44)
        at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:45)
        at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:30)
        at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
        at org.gradle.util.Swapper.swap(Swapper.java:38)
        at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:62)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:82)
        at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
        at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:122)
        at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
        at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:295)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'org.ajoberstar.grgit']
        at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:150)
        at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:125)
        at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator$3.run(DefaultPluginRequestApplicator.java:151)
        at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:225)
        ... 92 more
Caused by: org.gradle.api.plugins.PluginInstantiationException: Could not create plugin of type 'GrgitPlugin'.
        at org.gradle.api.internal.plugins.DefaultPluginManager.instantiatePlugin(DefaultPluginManager.java:74)
        at org.gradle.api.internal.plugins.DefaultPluginManager.producePluginInstance(DefaultPluginManager.java:183)
        at org.gradle.api.internal.plugins.DefaultPluginManager.addPlugin(DefaultPluginManager.java:159)
        at org.gradle.api.internal.plugins.DefaultPluginManager.access$200(DefaultPluginManager.java:47)
        at org.gradle.api.internal.plugins.DefaultPluginManager$AddPluginBuildOperation.run(DefaultPluginManager.java:252)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:144)
        ... 95 more
Caused by: java.lang.NoClassDefFoundError: org/ajoberstar/grgit/exception/GrgitException
        at org.gradle.api.internal.DependencyInjectingInstantiator.selectConstructor(DependencyInjectingInstantiator.java:144)
        at org.gradle.api.internal.DependencyInjectingInstantiator.access$200(DependencyInjectingInstantiator.java:36)
        at org.gradle.api.internal.DependencyInjectingInstantiator$2.transform(DependencyInjectingInstantiator.java:67)
        at org.gradle.api.internal.DependencyInjectingInstantiator$2.transform(DependencyInjectingInstantiator.java:61)
        at org.gradle.cache.internal.CrossBuildInMemoryCacheFactory$DefaultCrossBuildInMemoryCache.get(CrossBuildInMemoryCacheFactory.java:121)
        at org.gradle.api.internal.DependencyInjectingInstantiator.newInstance(DependencyInjectingInstantiator.java:61)
        at org.gradle.api.internal.plugins.DefaultPluginManager.instantiatePlugin(DefaultPluginManager.java:72)
        at org.gradle.api.internal.plugins.DefaultPluginManager.producePluginInstance(DefaultPluginManager.java:183)
        at org.gradle.api.internal.plugins.DefaultPluginManager.addPlugin(DefaultPluginManager.java:159)
        at org.gradle.api.internal.plugins.DefaultPluginManager.access$200(DefaultPluginManager.java:47)
        at org.gradle.api.internal.plugins.DefaultPluginManager$AddPluginBuildOperation.run(DefaultPluginManager.java:252)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:144)
        at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:125)
        at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator$3.run(DefaultPluginRequestApplicator.java:151)
        at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:225)
        at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:148)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:184)
        at org.gradle.configuration.BuildOperationScriptPlugin$1.run(BuildOperationScriptPlugin.java:61)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.configuration.BuildOperationScriptPlugin.apply(BuildOperationScriptPlugin.java:58)
        at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:41)
        at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
        at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:64)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.access$100(LifecycleProjectEvaluator.java:34)
        at org.gradle.configuration.project.LifecycleProjectEvaluator$ConfigureProject.run(LifecycleProjectEvaluator.java:110)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:50)
        at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:667)
        at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:136)
        at org.gradle.execution.TaskPathProjectEvaluator.configure(TaskPathProjectEvaluator.java:35)
        at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:60)
        at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
        at org.gradle.initialization.DefaultGradleLauncher$ConfigureBuild.run(DefaultGradleLauncher.java:261)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
        at org.gradle.initialization.DefaultGradleLauncher.configureBuild(DefaultGradleLauncher.java:173)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:132)
        at org.gradle.initialization.DefaultGradleLauncher.getConfiguredBuild(DefaultGradleLauncher.java:110)
        at org.gradle.internal.invocation.GradleBuildController$2.call(GradleBuildController.java:87)
        at org.gradle.internal.invocation.GradleBuildController$2.call(GradleBuildController.java:84)
        at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:152)
        at org.gradle.internal.invocation.GradleBuildController.doBuild(GradleBuildController.java:100)
        at org.gradle.internal.invocation.GradleBuildController.configure(GradleBuildController.java:84)
        at org.gradle.tooling.internal.provider.runner.ClientProvidedBuildActionRunner.run(ClientProvidedBuildActionRunner.java:64)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
        ... 54 more
Caused by: java.lang.ClassNotFoundException: org.ajoberstar.grgit.exception.GrgitException
        ... 112 more


* Get more help at https://help.gradle.org

BUILD FAILED in 0s

However v1.4.20 doesn't exhibit the same problem. For example

plugins {
    id 'java'
    id "org.ajoberstar.grgit" version "2.1.1"
    id "com.gorylenko.gradle-git-properties" version "1.4.20"
}

produces

$  ./gradlew clean assemble                                                                                                                                           
BUILD SUCCESSFUL in 0s
4 actionable tasks: 4 executed

Add support for submodules

Hi,

could you please add support for submodules?

I have a main project with several submodules that use gradle-git-properties, trying to build them fails because there is no .git folder inside the submodule:

09:04:42.158 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':generateGitProperties'. 09:04:42.160 [ERROR] [org.gradle.BuildExceptionReporter] > org.eclipse.jgit.errors.RepositoryNotFoundException: repository not found: /myProject/myProject-server

I think changing this def repo = Grgit.open(dir: project.gitProperties.gitRepositoryRoot ?: project.rootProject.file('.')) to this def repo = Grgit.open(currentDir: project.gitProperties.gitRepositoryRoot ?: project.rootProject.file('.')) may fix the issue, see ajoberstar/grgit#64 (comment)

Thank you,
Tobias

Build fails if git repo hasn't yet been initialized for project

As part of an organization we've modified the Spring Initializr (https://start.spring.io) so that it generates a cradle-based project which includes the gradle-git-properties plugin pre-wired into the build. The issue we're having is that once someone creates a project they may not have checked their code into a git repo yet. Not doing that - they are unable to build their project:

$ ./gradlew build
Build cache is an incubating feature.
Using directory (/Users/user/.gradle/caches/build-cache-1) as local build cache, push is enabled.
:bootBuildInfo UP-TO-DATE
:compileJava UP-TO-DATE
:generateGitProperties FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generateGitProperties'.
> org.eclipse.jgit.errors.RepositoryNotFoundException: repository not found: /Users/user/Desktop/mycompany-spring-starter

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

I can put in a workaround by adding this to the build.gradle:

generateGitProperties {
	onlyIf {
		!source.isEmpty()
	}
}

I think if you added the @SkipWhenEmpty annotation on top of the @InputFiles annotation on GenerateGitPropertiesTask.getSource() method inside GitPropertiesPlugin then all consumers of your plugin would simply get it for free.

Error using version 1.5.0 | Execution failed for task ':generateGitProperties'.

spring-boot-version: 1.5.13

plugin version:
id "com.gorylenko.gradle-git-properties" version "1.5.0"

...
11:57:03.314 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Resolve org.eclipse.jgit.ui.jar (org.eclipse.jgit:org.eclipse.jgit.ui:5.0.0.201805301535-rc2)' completed
... 
11:57:03.323 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Resolve org.eclipse.jgit.jar (org.eclipse.jgit:org.eclipse.jgit:5.0.0.201805301535-rc2)' completed
...
Execution failed for task ':generateGitProperties'.
> No signature of method: org.eclipse.jgit.internal.storage.file.FileRepository.getRef() is applicable for argument types: (java.lang.String) values: [HEAD]
  Possible solutions: getAt(java.lang.String), getFS(), grep(), exactRef(java.lang.String), findRef(java.lang.String), getAllRefs()```

Improve the logic to initialize only Git properties which will be used

Currently the plugin will initialize all Git properties even when the keys config is used to specified only some specific properties.
We should improve the logic to initialize only the properties will be used to improve the performance/stability of the plugin. For example, we could use Groovy closures to do this.

repository not found when .git is on a mounted drive.

I have read other bug reports that suggest that this is solved, however it is still occuring under the following conditions:
Virtualbox VM Ubuntu 16.04
Mounted VM harddisk on /home/dennis/dev/project (project is the mounted folder containing the .git)

  • What went wrong:
    Execution failed for task ':backend:generateGitProperties'.

org.eclipse.jgit.errors.RepositoryNotFoundException: repository not found: /home/dennis/dev/project/.git/objects/pack

I checked and the folder does exist...

I did some analyses and came to the conclusion that the mount is causing this issue to reveal itself.
Building the same project in a non mounted folder, worked like a charm.

This seems to be introduced in version 1.4.18+.. Version 1.4.17 works fine.

Cheers,
Dennis

Git metadata folder must be on the same project level of gradle.build

Hi @n0mer,

Check this example: https://github.com/ErnestOrt/Trampoline

I cannot use the plugin on microservice-example-gradle (unless I manually copy&past git folder from its parent) since it complains with the following error:

Execution failed for task ':generateGitProperties'.
org.eclipse.jgit.errors.RepositoryNotFoundException: repository not found: C:\Users\Ernest\Documents\GitHub\Trampoline\microservice-example-gradle

I would like to know if this situation is a minimum requirement to make pluggin worked.
If not:

  • Is there any work around?
  • Are any enhancements planned to improve this scenario?

Thanks in advance and also I would like to congratulate this open source team 🥇. Great work!

Regards,
Ernest

Getting gradle error when using the plugin

Error:(15, 0) Task with name 'classes' not found in root project 'XXX'.

gradle.build

buildscript {
    repositories {
        mavenLocal()
        jcenter()
        maven { url 'http://repo.spring.io/plugins-release' }
        maven { url 'http://repo.spring.io/milestone' }
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: spring_boot_version
    }
}

plugins {
    id "com.gorylenko.gradle-git-properties" version "1.4.7"
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'

sourceCompatibility = 1.8
targetCompatibility = 1.8

group = 'com.intel.swiss.myapp'
version = '0.0.1.SNAPSHOT'

bootRepackage {
    executable = true
    mainClass = 'com.intel.swiss.myapp.Application'
}

bootRun {
    addResources = true
}

springBoot {
    mainClass = 'com.intel.swiss.myapp.Application'
}

test {
    println 'Starting the Unit and Integration test'

    doFirst {
        if (project.hasProperty('Debug'))
        {
            println "Tests Classpath: "
            classpath.getFiles().each() { println it }
        }
    }

    testLogging.exceptionFormat="full"
    testLogging.showStandardStreams = true

    beforeTest { descriptor ->
        logger.lifecycle("Running test: " + descriptor)
    }

    reports.html.enabled = false
}

task cucumberTest(type: Test) {
    println 'Starting the Cucumber test'
    include '**/CucumberTest*'
}

test.finalizedBy(cucumberTest)

task testReport(type: TestReport) {
    println 'Executing testReport'
    destinationDir = file("$buildDir/reports/tests")
    reportOn test
    reportOn cucumberTest
}

cucumberTest.finalizedBy(testReport)

group 'com.intel.swiss.myapp'
version '0.0.1-SNAPSHOT'

configurations {
    providedRuntime
}

repositories {
    maven { url 'http://dl.bintray.com/readytalk/maven' }
    maven { url 'http://repo.spring.io/milestone' }
    maven { url 'http://repo.spring.io/snapshot' }
    maven { url 'https://repository.jboss.org/nexus/content/repositories/releases' }
    maven { url 'http://repo.maven.apache.org/maven2' }
    maven { url 'http://swiss-maven-repository.intel.com:8081/nexus/content/repositories/releases/' }
    maven { url 'http://swiss-maven-repository.intel.com:8081/nexus/content/repositories/snapshots/' }
}



dependencies {

//    compile group: 'com.intel.swiss', name: 'spring-cloud-common', version: '0.0.1.SNAPSHOT'

    /* Test */
    testCompile group: 'info.cukes', name: 'cucumber-junit', version: cucumber_version
    testCompile group: 'info.cukes', name: 'cucumber-spring', version: cucumber_version
    testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: spring_boot_version
    testCompile group: 'com.jayway.jsonpath', name: 'json-path', version: json_path_version
}

processResources {
    expand(project.properties)
}

compileJava.dependsOn(processResources)

clean {
    delete "target"
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

'repository not found' error

I have a project in a git repo that I've checked out locally and when I try to run gradle build I experience the following error:

...
:generateGitProperties FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generateGitProperties'.
> org.eclipse.jgit.errors.RepositoryNotFoundException: repository not found: /home/rob/Work/IdeaProjects/my-project/.git/logs/refs/heads
...

The directory referred to above exists and the current branch is represented beneath it. I'd appreciate any tips to resolve this. I've tried removing the directory and cloning the repo again from scratch but it doesn't appear to make any difference.

By default, git.commit.time should be formatted with dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" and dateFormatTimeZone = "${user.timezone}"

Spring boot expects git.commit.time in the format of
yyyy-MM-dd’T’HH:mm:ssZ
(see https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-git-info)

The maven-git-commit-id-plugin also uses default configs when generating git.commit.time value
dateFormat = yyyy-MM-dd'T'HH:mm:ssZ
dateFormatTimeZone = ${user.timezone}

Currently this Gradle plugin generates git.commit.time as a Unix timestamp value which is not very human friendly.

I suggest that we should format git.commit.id by default to a human friendly value using the below default configs:
dateFormat = yyyy-MM-dd'T'HH:mm:ssZ
dateFormatTimeZone = ${user.timezone}

Project repo url & dirty status

It would be great to be able to get github repo url on git.properties as well as if code has uncommit things as this plugin has:

<plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

Cheers!

Replace gitRepositoryRoot config key by dotGitDirectory config key

I suggest that we should make a change (which is not backward compatible) to remove gitRepositoryRoot config key and replace it by dotGitDirectory config key. There are several reasons for the suggestion:

  1. Consistency. To be consistent with maven git commit id plugin
  2. Flexibility of configuration. Currently gitRepositoryRoot must be configured to point to a parent folder which containing a subfolder with the name of ".git/" . This is not flexible enough to support for git modules (which using .git files or folders below ".git/modules/*")
  3. Behavior change. We cannot fix issues regarding gitRepositoryRoot (i.e. changing its behavior) and still use the old config name. Adding a new name would make the config complicated.

@n0mer Should we break the compatibility and replace the config key? If yes, we might also want to replace gradle-git-1.7.2 by grgit 2.x (to fix #52) and will support Java 8+ only. The plugin's major version should also be changed to 2.0 or something to indicate that it will not backward compatible.

Support multiple line commit messages

I'm not entirely sure if this is an issue for this plugin or not, but full commit messages that span multiple lines are not set correctly in the git.properties file. Example:

git.commit.message.full=The title
The message first line
The message second line

The message should be set like:

git.commit.message.full=The title\
The message first line\
The message second line

The plugin does not work with Java 7

The version of the plugin available via the plugin exchange does not work when the build is executed with a Java 7 JDK. This is because the classes are compiled for Java 8 and are therefore incompatible with Java 7.
As the code is Groovy anyways the plugin could be compiled with the Java 7 targetCompatibility to ensure the plugin in the exchange is backwards compatible to Java 7. This is needed by these poor souls still forced to use Java 7 by there environment.

RepositoryNotFoundException on jenkins

When we upgraded from 1.4.17 to 1.4.20 we started to get this error on our jenkins server.
No sure why...
`
Execution failed for task ':service:generateGitProperties'.

org.eclipse.jgit.errors.RepositoryNotFoundException: repository not found: /tmp/jenkins/workspace/ApiGateway-pull-requests/.git/objects/c2
`

generateGitProperties shows UP-TO-DATE after executing clean task

If generateGitProperties task generated git.properties and then the file is deleted (manually or by gradle clean), executing generateGitProperties task again will NOT re-generate the git.properties (because gradle thinks the output is UP-TO-DATE)
This is something related to gradle cache folder (.gradle/) of project folder so step 1 below is important to reproduce the issue

rep1.zip

Steps to reproduce: (sample project is attached)

  1. Delete build/ and .gradle/ from the project folder (if any). This step is important.

    c:\rep1> rmdir /s /q .gradle
    c:\rep1> rmdir /s /q build
    
  2. Run gradle jar to generate git.properties

    c:\rep1> gradle jar
    :compileJava
    :generateGitProperties
    :processResources UP-TO-DATE
    :classes
    :jar
    
    BUILD SUCCESSFUL
    
  3. Run gradle clean to delete build/ folder

    c:\rep1> gradle clean
    :clean
    
    BUILD SUCCESSFUL
    
  4. Run gradle jar again and verify that the git.properties is not re-generated

    c:\rep1> gradle jar
    :compileJava
    :generateGitProperties UP-TO-DATE
    :processResources UP-TO-DATE
    :classes
    :jar
    
    BUILD SUCCESSFUL
    

    The git.properties is not generated because (:generateGitProperties UP-TO-DATE)

  5. System information:

    C:\rep1>gradle -v
    
    ------------------------------------------------------------
    Gradle 2.12
    ------------------------------------------------------------
    
    Build time:   2016-03-14 08:32:03 UTC
    Build number: none
    Revision:     b29fbb64ad6b068cb3f05f7e40dc670472129bc0
    
    Groovy:       2.4.4
    Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
    JVM:          1.8.0_51 (Oracle Corporation 25.51-b03)
    OS:           Windows 7 6.1 amd64
    

Add support for Heroku builds/deploys

Hi,
It seems the gradle git plugin does not work with Heroku (the gradle buildpack). The plugin works a charm locally but when I deploy my app on Heroku through github I get this:

Execution failed for task ':bignibou-server:generateGitProperties'.
       > org.eclipse.jgit.errors.RepositoryNotFoundException: repository not found: /tmp/build_4554f9f0f404781365e453846c38e499/silteo-bignibou-site-ad93e406ac8e613a615778d617498dd057043ace

Unexpected token error

Hi,
I am trying to build the project and getting an exception on the GitPropertiesPlugin class. It seems the bracket is not properly closed at the right place.

`$ gradle build
Starting a Gradle Daemon, 1 busy and 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
:compileJava NO-SOURCE
:compileGroovystartup failed:

GitPropertiesPlugin.groovy: 101: unexpected token: , @ line 101, column 24.
, (KEY_GIT_DIRTY) : !repo.status().clean]
`

Thanks.

Add API to expose generated properties

Could you expose generated properties as map or provide some api for accessing generated values? I would like to use generated values in other tasks. As a workaround I do this in build.gradle:

ext {
    gitProps = new Properties()
}
// ...
task loadGitProperties(type: Task) {
    dependsOn tasks.generateGitProperties
    doLast {
        generateGitProperties.output.withInputStream { InputStream istr -> project.gitProps.load(istr) }
    }
}
// ...
// in some task other task:
"${-> gitProps['git.branch'] ?: 'not-set'}"

Just gitProperties['git.branch'] or gitProperties.find('git.branch') without additional custom code would make more sense.

"gitRepositoryRoot" config doesn't work with 1.4.21

All i'm using this plugin with Gradle 4.6. With 1.4.20 it works. On upgrading to 1.4.21 it cannot find my .git directory as it is at the project root. When I specify the gotGitDirectory it fails with the following error

* What went wrong:
A problem occurred evaluating root project 'api'.
> Could not set unknown property 'dotGitDirectory' for object of type com.gorylenko.GitPropertiesPluginExtension.

My gitProperties configuration looks like

gitProperties {
    gitRepositoryRoot = new File("${project.rootDir}/..")
    dotGitDirectory = new File("${project.rootDir}/.git")
    dateFormat = "yyyy-MM-dd'T'HH:mmZ"
    dateFormatTimeZone = "Asia/Kolkata"
}

Here is my build.gradle configuration

dependencies {
                classpath( "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}" )
                classpath( 'io.spring.gradle:dependency-management-plugin:1.0.4.RELEASE' )
                classpath( 'gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:1.4.21' )
        }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.gorylenko.gradle-git-properties'

Do I have the correct configuration? Rolling back to 1.4.20 for now.

Date format does not work

Hi,

I've been trying the dateFormat feature with no success. I use the following config:

gitProperties {
    dateFormat = "yyyy-MM-dd'T'HH:mmZ"
    dateFormatTimeZone = "GMT"
}

but the commit.time is still displayed as a number.

Allow branch name to be overridden using env vars

In Jenkins, some SCM plugins checkout a branch using git checkout -f ...:

Checking out Revision faf8f0c185c1cb091265f59027271ae1df18e850 (lorem/ipsum)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f faf8f0c185c1cb091265f59027271ae1df18e850
Commit message: "Lorem ipsum"
 > git rev-list 4053285d4f883630148ff48f38b50cace4d8d49f # timeout=10

When this happens, the branch name in git.properties is set to HEAD.

However, in the Jenkins environment the BRANCH_NAME env var preserves the actual branch name.

gradle-git-properties needs an option to query an env var for branch name, rather than .git/....

Bump version to 1.5.0

Hi,

First of all, thanks for the plugin.

  • A lot of important changes have been added since last bump 1.4.21. Could we expect the version 1.5.0 to be bumped and available on the plugins.gradle.org repository quite soon?
  • Also, because the repository is not having any tag, it's very hard and confusing to have clear idea of the state of the plugin for a given version : the current version suggested in your README.md is clearly not providing half of the API described in the same doc file. Could you please push a git tag of the version you bump so that we can have snapshots of the plugin for a given version? We could then easily differentiate master which is the trunk dev branch, and the tags which are fixed releases.

Support git-describe

maven-git-commit-id-plugin supports git-describe. In particular, it supports marking "dirty" working copies, so it's clear whether a given build was from a completely clean checkout. Any modification to a committed file will produce a dirty state, leading to a build that may not be reproducible.

Should not apply Java plugin automatically to non-Java projects

I added this plugin into a non-Java project and this plugin automatically applied java plugin (which also added Java-specific tasks: classes , buildDependents, buildNeeded, jar, testClasses). See details below.

I believe that if this plugin is used in a non-Java project, it should NOT automatically apply Java plugin to project (because users still can invoke the 'generateGitProperties' manually to generate git.properties when needed, and this plugin is a general purpose, not Java specific plugin)

Here is the details of the issue:

BEFORE:
--------- build.gradle -------------

apply plugin: 'c'
 
model { 
    components {
        main(NativeExecutableSpec)   
    }
}
> gradle tasks

Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
clean - Deletes the build directory.
installMainExecutable - Installs a development image of executable 'main:executable'
mainExecutable - Assembles executable 'main:executable'.

AFTER:
--------- build.gradle -------------

plugins {
  id "com.gorylenko.gradle-git-properties" version "1.4.21"
}
apply plugin: 'c'
 
model { 
    components {
        main(NativeExecutableSpec)   
    }
}
> gradle tasks

Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
generateGitProperties
installMainExecutable - Installs a development image of executable 'main:executable'
jar - Assembles a jar archive containing the main classes.
mainExecutable - Assembles executable 'main:executable'.
testClasses - Assembles test classes.

allow soft failure when not a git repo

I have exported a git repo into another directory and I am working with it. Since it does not have git metadata, the gradle-git-properties plugin fails.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generateGitProperties'.
> org.eclipse.jgit.errors.RepositoryNotFoundException: repository not found: /Users/kgeis/temp/phoebe

I would like for it not to fail.

task 'classes' not found

I tried adding this to my build.gradle file and ran into the following error when building:

* What went wrong:
An exception occurred applying plugin request [id: 'com.gorylenko.gradle-git-properties', version: '1.4.10']
> Failed to apply plugin [id 'com.gorylenko.gradle-git-properties']
   > Task with name 'classes' not found in root project 'my-project'.

It looks like it assumes that I will have a classes task and I don't.

Add support for Git Worktrees

Git worktrees allow to checkout multiple working copies at the same time, more here: https://git-scm.com/docs/git-worktree. This plugin doesn't work when the build is triggered within a worktree, it fails with the following error (including just the root cause):

Caused by: org.eclipse.jgit.errors.RepositoryNotFoundException: repository not found: /Users/wujek/Development/IdeaProjects/sample-project/worktrees/develop
at org.eclipse.jgit.lib.BaseRepositoryBuilder.build(BaseRepositoryBuilder.java:581)
at org.eclipse.jgit.api.Git.open(Git.java:116)
at org.eclipse.jgit.api.Git.open(Git.java:99)
at org.eclipse.jgit.api.Git$open.call(Unknown Source)
at org.ajoberstar.grgit.operation.OpenOp.call(OpenOp.groovy:84)
at org.ajoberstar.grgit.operation.OpenOp.call(OpenOp.groovy)
at java_util_concurrent_Callable$call$2.call(Unknown Source)
at org.ajoberstar.grgit.util.OpSyntaxUtil.tryOp(OpSyntaxUtil.groovy:45)
at org.ajoberstar.grgit.Grgit$__clinit__closure1.doCall(Grgit.groovy:193)
at com.gorylenko.GitPropertiesPlugin$GenerateGitPropertiesTask.generate(GitPropertiesPlugin.groovy:50)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
... 75 more

More info: the project (its initial clone) is located at /Users/wujek/Development/IdeaProjects/sample-project, and I then created a worktree using 'git worktree add worktrees/develop develop'.

jgit seems to support it already, at least the latest versions: https://bugs.eclipse.org/bugs/show_bug.cgi?id=477475.

Upgrade gradle-git dependency version (currently 1.4.2) to avoid annoying jgit message (Cannot run program "bash")

Whenever running the build with this plugin, I see below message (from jgit 3.x ) although everything works well

java.io.IOException: Cannot run program "bash" (in directory "..."): CreateProcess error=2, The system cannot find the file specified

If gradle-git version can be updated to a newer version (1.4.x), it will use new jgit 4.x and this message will not be displayed anymore. (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=463349)

Thanks.

Timestamp causes JAR hash change

#Fri Mar 04 14:27:29 CET 2016
git.commit.id=8ce443f105008d621430efe33f59816a77c428d8
git.commit.time=1457050640
....

The timestamp comment written to file causes gradle to think the resultant JAR file has changed even if nothing else has (and also causes issues with docker since it thinks the whole artifact has been modified). Can you suppress it?

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.