当我合并到另一个build.gradle文件以将两个不同的功能集成到一个文件时,它显示如下错误-
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。
答案 0 :(得分:1)
在合并的脚本中,您将混合使用Gradle插件的两种符号:buildscript{}
和plugins {}
DSL(在此处查看有关这两种符号的更多信息:https://docs.gradle.org/current/userguide/plugins.html#sec:binary_plugins)>
虽然可以同时使用两种符号,但存在Gradle约束:您必须将plugins{}
块放置在脚本的第一个位置,但是如果您还有buildscript{}
块,则必须放在plugins{}
块之前。
(我会在官方文档中尝试找到此约束的指针)
编辑:请参见plugins{}
块约束here的描述:
plugins {}块也必须是buildscript中的顶级语句。它不能嵌套在另一个结构中(例如,if语句或for循环)
因此:只需将buildscript {}
块移动到脚本顶部即可。
注意:更好的解决方案是摆脱buildscript {}
块,这是“旧”语法:
使用:
plugins {
id "io.spring.dependency-management" version "1.0.7.RELEASE"
}
代替
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:1.0.7.RELEASE"
}
}