Reputation: 55
Is it possible to use @Grab inside a Gradle build.gradle file?
My understanding is that Gradle build scripts are written in Groovy and Grape/@Grab is built into Groovy.
But if i attempt to add a @Grab annotation into a build.gradle file it doesn't work.
e.g. adding:
@Grab(group='org.springframework', module='spring-orm', version='3.2.5.RELEASE')
import org.springframework.jdbc.core.JdbcTemplate
it gives me the error
org.gradle.groovy.scripts.ScriptCompilationException: Could not compile build file.
Is this possible?
Upvotes: 3
Views: 1295
Reputation: 24498
According to this post, the answer is no, we can't use @Grab
.
However, there is an equivalent way to declare a dependency and add it to the classpath, as shown below (usage for the example: 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()
}
}
Upvotes: 4