Я получил ошибку, используя этот файл build.grafle и не знаю, как это исправить - PullRequest
0 голосов
/ 16 мая 2018

Вот ошибка:

FAILURE: сборка не удалась с исключением.

  • Где: файл сборки '/ home / wieland / GitGradlePackaging / build.gradle 'line: 22 * ​​1008 *

  • Что пошло не так: возникла проблема при оценке корневого проекта' GitGradlePackaging '.

    Не удалось получить неизвестное свойство' org 'для объектатипа 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, так как я только начинаю изучать его!Заранее спасибо:)

1 Ответ

0 голосов
/ 16 мая 2018

Вы должны переместить определение 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: запуск до остальной части сборки и подготовка установки.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...