From 16af5fb65c8fb5f8ca88106edf0cb387bff1184f Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 31 Dec 2019 14:53:35 -0500 Subject: [PATCH] GH-1344: Enable updateCopyrights onlyIf grgit (#1345) * GH-1344: Enable updateCopyrights onlyIf grgit Fixes https://github.com/spring-projects/spring-kafka/issues/1344 Sometimes people build our project outside of Git repository * Make the `updateCopyrights` Gralde task conditional on the presence of `grgit` object initialized by the `org.ajoberstar.grgit` when Git repository is present. Otherwise it is `null` * Check for `grgit` presence when we try to gather `modifiedFiles` * * Check for `.git` dir before applying `grgit` plugin --- build.gradle | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 21db6f43..9c3135d4 100644 --- a/build.gradle +++ b/build.gradle @@ -17,13 +17,19 @@ plugins { id 'idea' id 'org.sonarqube' version '2.7.1' id 'org.asciidoctor.convert' version '1.6.1' - id 'org.ajoberstar.grgit' version '3.1.1' + id 'org.ajoberstar.grgit' version '3.1.1' apply false id 'io.spring.nohttp' version '0.0.3.RELEASE' id 'io.spring.dependency-management' version '1.0.8.RELEASE' apply false } apply plugin: 'io.spring.nohttp' +def gitPresent = new File('.git').exists() + +if(gitPresent) { + apply plugin: 'org.ajoberstar.grgit' +} + description = 'Spring Kafka' ext { @@ -35,8 +41,11 @@ ext { linkScmDevConnection = 'git@github.com:spring-projects/spring-kafka.git' docResourcesVersion = '0.1.0.RELEASE' - modifiedFiles = + + if (gitPresent) { + modifiedFiles = files(grgit.status().unstaged.modified).filter{ f -> f.name.endsWith('.java') || f.name.endsWith('.kt') } + } assertjVersion = '3.15.0' googleJsr305Version = '3.0.2' @@ -170,8 +179,10 @@ subprojects { subproject -> task updateCopyrights { - onlyIf { !System.getenv('TRAVIS') && !System.getenv('bamboo_buildKey') } - inputs.files(modifiedFiles.filter { f -> f.path.contains(subproject.name) }) + onlyIf { gitPresent && !System.getenv('TRAVIS') && !System.getenv('bamboo_buildKey') } + if (gitPresent) { + inputs.files(modifiedFiles.filter { f -> f.path.contains(subproject.name) }) + } outputs.dir('build') doLast {