首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >分级生成文件显示生成过程中的错误。

分级生成文件显示生成过程中的错误。
EN

Stack Overflow用户
提问于 2019-05-14 11:35:05
回答 1查看 1.2K关注 0票数 0

当我合并到不同的build.gradle文件中,将两个不同的功能集成到一个时,它会显示以下错误:

代码语言:javascript
复制
startup failed:
build file 'C:\Users\sobhit.s\Pictures\API-Update\build.gradle': 89: all buildscript {} blocks must appear before any plugins {} blocks in the script

See https://docs.gradle.org/4.0/userguide/plugins.html#sec:plugins_block for information on the plugins {} block

 @ line 89, column 1.
   buildscript {
   ^

1 error

Open File

import java.util.concurrent.TimeUnit

plugins {
    id 'java'
}

apply plugin: 'java'    
group 'api_automation'
version '1.0-SNAPSHOT'   
sourceCompatibility = 1.8    
repositories {
    mavenCentral()
} 
test {
    reports {
        junitXml.enabled = true
        html.enabled = false
        reports.junitXml.destination = file("test-output/reports/")
    }
    useTestNG()
            {
                useDefaultListeners = true
                options.suites("src/test/java/testApi_Test_Scripts/smsApiAutomationSuite.xml")
                            }
}
sourceSets {
    main {
        runtimeClasspath = files(output.resourcesDir) + runtimeClasspath
    }
    test {
        runtimeClasspath = files(output.resourcesDir) + runtimeClasspath
    }
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
    }
}

apply plugin: "io.spring.dependency-management"
dependencyManagement {
    imports {
        mavenBom 'software.amazon.awssdk:bom:2.0.0'
    }
}
dependencies {
    compile group: 'io.rest-assured', name: 'rest-assured', version: '3.0.2'
    testCompile group: 'org.testng', name: 'testng', version: '6.8.+'
    //An assertion library that is better than JUnit defaults
    testCompile 'org.easytesting:fest-assert-core:2.0M10'
    //Better reporting for testng.  It outputs a nice html report
    testCompile 'org.uncommons:reportng:1.1.4'
    compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.15'
    compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
    compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
    compile group: 'com.googlecode.htmlcompressor', name: 'htmlcompressor', version: '1.5.2'
    compile group: 'commons-dbutils', name: 'commons-dbutils', version: '1.6'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
    compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5'
    compile group: "com.github.fge", name: "json-schema-validator", version: "2.2.6"
    compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
    compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
    compile group: 'org.json', name: 'json', version: '20160810'
    compile group: 'org.uncommons', name: 'reportng', version: '1.1.4'
    compile group: 'com.google.code.guice-repository', name: 'guice-repository', version: '2.1.0'
    compile group: 'org.easytesting', name: 'fest-assert-core', version: '2.0M10'
    compile group: 'org.uncommons', name: 'reportng', version: '1.1.4'
    compile group: 'org.apache.commons', name: 'commons-csv', version: '1.5'
    compile group: 'org.apache.commons', name: 'commons-exec', version: '1.3'
    compile group: 'com.opencsv', name: 'opencsv', version: '4.1'
    compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
    compile 'com.relevantcodes:extentreports:2.41.2'
    compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.0'
    compile group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
    compile 'software.amazon.awssdk:kinesis'
    compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.534'
    compile group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: '1.11.539'
    compileClasspath group: 'org.testng', name: 'testng', version: '6.8.+'
}
test {
    ignoreFailures = true
}

这是合并后的build.gradle。另外,我也不确定创建build.gradle的标准方法是什么。任何帮助都会很感激的。

从那时起,我添加了build.script和mavem bom,这是一个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-14 12:21:01

在您合并的脚本中,您混合了用于应用Gradle插件的两个符号:buildscript{}表示法和plugins {} DSL (参见有关这两个符号的更多信息:插件 )

虽然这两种符号都可以混合,但是有一个Gradle约束:您必须将plugins{}块放在脚本中的第一个位置,但是如果您也有一个buildscript{}块,那么它必须放在plugins{}块之前。(我将尝试在正式文档中找到指向此约束的指针)

编辑:参见对plugins{}块违禁品的描述,这里

插件{}块也必须是构建脚本中的顶级语句。它不能嵌套在另一个构造中(例如if-语句或for-循环)。

因此:只需移动脚本顶部的buildscript {}块即可。

注意:更好的解决方案是去掉buildscript {}块,这是“旧”语法:

用途:

代码语言:javascript
复制
plugins {
  id "io.spring.dependency-management" version "1.0.7.RELEASE"
}

而不是

代码语言:javascript
复制
buildscript {
  repositories {
      mavenCentral()
  }
  dependencies {
     classpath "io.spring.gradle:dependency-management-plugin:1.0.7.RELEASE"
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56129492

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档