出现如下错误,当我使用此命令“bash ./gradlew build”编译代码时
Unresolved reference :grgit
build.gradle.kts:

import org.apache.tools.ant.filters.FixCrLfFilter
import org.apache.tools.ant.filters.ReplaceTokens
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.text.SimpleDateFormat
import java.util.Date

plugins {
   java
   kotlin("jvm") version "1.3.60"
   `maven-publish`
   id("com.github.xxxxx") version "5.2.0"
   id("org.ajoberstar.grgit") version "4.0.2"

 }
val vertx = "3.8.5"
dependencies {
implementation("org.apache.logging.log4j:log4j-api:2.13.0")
implementation("org.apache.logging.log4j:log4j-core:2.13.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2")
implementation(kotlin("stdlib-jdk8"))
implementation("io.vertx:vertx-core:${vertx}")
implementation("io.vertx:vertx-rx-java2:${vertx}")
implementation("io.vertx:vertx-web:${vertx}")
implementation("io.reactiverse:elasticsearch-client-rxjava2:0.8.2-ec7.6.2")
implementation("org.yaml:snakeyaml:1.25")
implementation("io.vertx:vertx-mysql-client:${vertx}")
implementation("io.vertx:vertx-shell:${vertx}")
testImplementation("junit", "junit", "4.12")
testImplementation("io.vertx", "vertx-unit", vertx)
runtimeOnly("io.vertx:vertx-hazelcast:${vertx}")
}
val gitStatus = grgit.status()
val versionTimestamp = SimpleDateFormat("yyyyMMddHHmm").format(Date())
val versionCommit = grgit.head().Id
var currentBranchName = grgit.branch.current().getName();
if (currentBranchName.equals("HEAD", true)) { /* happens on jenkins */
   val usedRemoteBranch = grgit.branch.current()
出现如下错误
脚本编译错误:
69行:val gitStatus = grgit.status()
^ Unresolved reference :grgit
第71行:val versionCommit = grgit.head()。Id
^ Unresolved reference :grgit
第72行:var currentBranchName = grgit.branch.current()。getName();
^ Unresolved reference :grgit
第74行:val usedRemoteBranch = grgit.branch.current()
^ Unresolved reference :grgit
在build.gradle.kts中。
您能帮我解决这个问题吗?

最佳答案

您尚未声明grgit变量。
您可以通过以下方式获取Grgit实例:

import org.ajoberstar.grgit.Grgit
...
val grgit = Grgit.open(mapOf("currentDir" to project.rootDir))
引用:http://ajoberstar.org/grgit/index.html

10-04 12:21