是否可以在Gradle build.gradle文件中使用@Grab?
我的理解是,Gradle构建脚本是用Groovy编写的,而Grab/@Grab是内置在Groovy中的。
但是,如果我尝试将@Grab注释添加到build.gradle文件中,它将不起作用。
例如,添加:
@Grab(group='org.springframework', module='spring-orm', version='3.2.5.RELEASE')
import org.springframework.jdbc.core.JdbcTemplate它会给我一个错误
org.gradle.groovy.scripts.ScriptCompilationException: Could not compile build file.这个是可能的吗?
发布于 2018-05-04 02:19:08
根据this post的说法,答案是不,我们不能使用@Grab。
但是,有一种等价的方法可以声明依赖项并将其添加到类路径中,如下所示(示例的用法:gradle go):
buildscript {
repositories {
jcenter()
}
dependencies {
classpath group: 'org.springframework', name: 'spring-orm', version: '3.2.5.RELEASE'
}
}
import org.springframework.jdbc.core.JdbcTemplate
task go() {
doLast {
println 'TRACER : ' + JdbcTemplate.class.getSimpleName()
}
}https://stackoverflow.com/questions/50158905
复制相似问题