Gradle 我使用这个build.grafle文件和don';我不知道如何修理它
以下是错误: 失败:生成失败,出现异常Gradle 我使用这个build.grafle文件和don';我不知道如何修理它,gradle,build.gradle,Gradle,Build.gradle,以下是错误: 失败:生成失败,出现异常 其中:构建文件“/home/wieland/GitGradlePackaging/Build.gradle”行:22 错误:评估根项目“GitGradlePackage”时出现问题 无法获取类型为org.gradle.api.internal.initialization.DefaultScriptHandler的对象的未知属性“org” 这是我的build.gradle文件: /* * This file was generated by the
- 其中:构建文件“/home/wieland/GitGradlePackaging/Build.gradle”行:22
- 错误:评估根项目“GitGradlePackage”时出现问题 无法获取类型为org.gradle.api.internal.initialization.DefaultScriptHandler的对象的未知属性“org”
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/4.6/userguide/tutorial_java_projects.html
*/
//From example: http://mrhaki.blogspot.co.at/2015/04/gradle-goodness-use-git-commit-id-in.html
buildscript {
repositories {
jcenter()
}
dependencies {
//Add dependencies for build script, so we can access Git from our build script
classpath 'org.ajoberstar:grgit:1.1.0'
}
def git = org.ajoberstar.grgit.Grgit.open(file('.'))
//To save Githash
def githash = git.head().abbreviatedId
}
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building an application
id 'application'
// Apply the groovy plugin to also add support for Groovy (needed for Spock)
id 'groovy'
id 'distribution'
}
// Set version
project.version = mainProjectVersion + " - " + githash
project.ext.set("wholeVersion", "$project.version - $githash")
project.ext.set("buildtimestamp", "2000-01-01 00:00")
def versionfilename = "versioninfo.txt"
def GROUP_DEBUG = 'Debug'
// Task to print project infos
task debugInitialSettings {
group = GROUP_DEBUG
doLast {
println 'Version: ' + project.wholeVersion
println 'Timestamp: ' + project.buildtimestamp
println 'Filename: ' + project.name
}
}
// To add the githash to zip
task renameZip {
doLast {
new File ("$buildDir/distributions/$project.name-${project.version}.zip")
.renameTo ("$buildDir/distributions/$project.name-${project.wholeVersion}.zip")
}
}
distZip.finalizedBy renameZip
// To add the githash to tar
task renameTar{
doLast {
new File ("$buildDir/distributions/$project.name-${project.version}.tar")
.renameTo ("$buildDir/distributions/$project.name-${project.wholeVersion}.tar")
}
}
distTar.finalizedBy renameTar
// Define the main class for the application
mainClassName = 'App'
dependencies {
// This dependency is found on compile classpath of this component and consumers.
compile 'com.google.guava:guava:23.0'
// Use the latest Groovy version for Spock testing
testCompile 'org.codehaus.groovy:groovy-all:2.4.13'
// Use the awesome Spock testing and specification framework even with Java
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
testCompile 'junit:junit:4.12'
}
// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
//To generate Testreports as HTML
test {
reports {
junitXml.enabled = false
html.enabled = true
}
}
distributions {
main {
contents {
from { 'build/docs' }
into ('reports') {
from 'build/reports'
}
}
}
}
//To make sure that test and javadoc ran before zip and tar
distTar.dependsOn test
distZip.dependsOn test
distTar.dependsOn javadoc
distZip.dependsOn javadoc
请记住,我对gradle了解不多,因为我才刚刚开始学习它!
提前感谢:)您必须将githash定义移到
buildscript
块之外
buildscript {
repositories {
jcenter()
}
dependencies {
//Add dependencies for build script, so we can access Git from our build script
classpath 'org.ajoberstar:grgit:1.1.0'
}
}
def git = org.ajoberstar.grgit.Grgit.open(file('.'))
//To save Githash
def githash = git.head().abbreviatedId
原因是当逐行计算
buildscript
块时,其依赖项尚未加载。当对脚本的其余部分求值时,buildscript
块的依赖项已经加载。这实际上就是buildscript
块存在的原因:在构建的其余部分之前运行并准备安装。谢谢!现在它运行了一段时间,但随后出现以下错误:*其中:Build file'/home/wieland/GitGradlePackaging/Build.gradle'行:41*错误:评估根项目“GitGradlePackaging”时出现问题。>无法为org.gradle.api.project类型的根项目“GitGradlePackageing”获取未知属性“mainProjectVersion”。mainProjectVersion
从未定义。Nvm,我甚至不需要它