gpt4 book ai didi

android - 无法将JGit导入gradle构建脚本

转载 作者:行者123 更新时间:2023-12-03 05:31:23 24 4
gpt4 key购买 nike

我想在JGit脚本中使用app/gradle.build来获取当前标签来为我的android项目创建版本名称。

我已经在下面的根build.gradle中声明了依赖项

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
mavenCentral()
maven {
url "https://repo.eclipse.org/content/groups/releases/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.eclipse.jgit:org.eclipse.jgit:5.5.0.201909110433-r'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()

}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

但同步后,我的 app/build.gradle中仍然没有JGit
def versionNameFromTag() {
Git git = new Git(repository) // <- Unresolved Reference: Git
}

更新

我可以使用以下依赖项声明修复程序将JGit放入我的根 /build.gradle文件中
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
mavenCentral()
maven {
url "http://download.eclipse.org/jgit/maven"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.eclipse.jgit:org.eclipse.jgit:5.5.+"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()
}
}

// Now Compiles with JGit dependencies
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
import org.eclipse.jgit.lib.*
import org.eclipse.jgit.revwalk.*

但是我的 app/build.gradle仍然无法导入JGit
// Still doesn't compile
import org.eclipse.jgit.api.Git // <- Unresolved Reference: Git

def versionNameFromTag() {
Git git = new Git(repository) // <- Unresolved Reference: Git
}

最佳答案

每个Gradle脚本都是独立的,当您使用buildscript块添加依赖项时,这些依赖项在声明它们的脚本中是本地的。这些依赖项不会传播到所包含的项目。

您有几个选择,按优先顺序排列:

  • 通过included build in buildSrc 添加此依赖项,然后将其提供给所有项目。
  • 在所有需要jgit的脚本中复制声明
  • 关于android - 无法将JGit导入gradle构建脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59137479/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com