我想在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
}
答案 0 :(得分:0)
每个Gradle脚本都是独立的,并且当您使用buildscript
块添加依赖项时,这些依赖项对于声明它们的脚本而言是本地的。这些依赖项不会传播到所包含的项目。
按照偏好顺序,您有几个选择:
buildSrc
添加此依赖项,然后将其用于所有项目。jgit
的脚本中复制声明