plugins {
id 'java'
id 'war'
}
group 'com.example'
version '1.0-SNAPSHOT'
repositories {
maven{
url "https://maven.aliyun.com/nexus/content/groups/public/"
}
mavenCentral()
}
ext {
junitVersion = '5.8.2'
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
dependencies {
compileOnly('jakarta.servlet:jakarta.servlet-api:5.0.0')
implementation group: 'org.springframework', name: 'spring-web', version: '6.1.9'
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
test {
useJUnitPlatform()
}
要点:
1.配置文件是一个可运行脚本,与maven的配置文件pom.xml文件完全不同;
2.配置文件中
xxx{
}
是一个函数调用语句。xxx是函数名称,{ }是一个闭包(类似匿名函数),作为xxx函数的参数传入函数。
3.在groovy语言中,调用函数时,参数可以省略括号,多个参数用逗号分割。
如:
group 'com.example',相当于 group('com.example')。
id 'java',相当于 id('java')
4.调用函数如没有参数,则不能省略圆括号。
如:
mavenCentral(),不能写作mavenCentral。
5.参数加了冒号,表示将会组合成一个map类型的参数,冒号前为key,冒号后为value.
如:
implementation group: 'org.springframework', name: 'spring-web', version: '6.1.9',相当于
implementation(m),其中,m.group='org.springframework',m.name='pring-web', m.version= '6.1.9'