'Is it possible to use @Grab inside a Gradle build.gradle?
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?
Solution 1:[1]
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()
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Michael Easter |
