gpt4 book ai didi

gradle - 使用此build.grafle文件时出现错误,不知道如何解决

转载 作者:行者123 更新时间:2023-12-03 03:58:52 25 4
gpt4 key购买 nike

这是错误:

FAILURE: Build failed with an exception.

  • Where: Build file '/home/wieland/GitGradlePackaging/build.gradle' line: 22

  • What went wrong: A problem occurred evaluating root project 'GitGradlePackaging'.

    Could not get unknown property 'org' for object of type org.gradle.api.internal.initialization.DefaultScriptHandler.



  • 这是我的build.gradle文件:
    /*
    * 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块存在的原因:要在构建的其余部分之前运行并准备设置。

关于gradle - 使用此build.grafle文件时出现错误,不知道如何解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50366785/

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