groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <pa...@asert.com.au>
Subject Re: Convert @Grab to Grape.grab ?
Date Mon, 20 Jan 2020 22:32:07 GMT
It's certainly possible since that is what the compiler does. The compiler
goes the extra step and adds the jar onto the classpath at compilation time
as well but you might not need that.

>From a script you'd do something like:
groovy.grape.Grape.grab(classLoader: getClass().classLoader, group:
'com.oracle.ojdbc', module: 'ojdbc8', version: '19.3.0.0')

Depending on your context you might need to get the classloader in
a slightly different way.

Cheers, Paul.



On Tue, Jan 21, 2020 at 6:36 AM Nelson, Erick <Erick.Nelson@hdsupply.com>
wrote:

> Is it possible to convert a Grab annotation to a Grapes.grab call?
>
>
>
> Example:
>
> Convert this…
>
>
>
> @Grapes([
>
>   @GrabConfig(systemClassLoader=true),
>
>   @Grab('com.oracle:ojdbc6:11.2.0.1.0'),
>
> ])
>
> import groovy.sql.Sql
>
>
>
> to this…
>
>
>
> groovy.grape.Grape.grab(group:'com.oracle', module:'ojdbc6',
> version:'11.2.0.1.0')
>
>
>
>
>
> I’m assuming I’d need to add map entries for classLoader: and refObject:
> but I’m not sure how to assemble these if needed.
>
>
>
> I’d like to put the Grapes.grab call in my compiled library.  Is this even
> possible?
>
>
>
> My library connects to oracle like this…
>
>
>
> Sql.withInstanceOracle(user:'tauser03',name:'ecprd4') { sql -> }
>
>
>
> The static method withInstanceOracle is a metaClass method that under the
> hood calls this…
>
>
>
>
>
>     *static* Sql newInstance (Map map) {
>
>         // groovy.grape.Grape.grab(group:'com.oracle', module:'ojdbc6',
> version:'11.2.0.1.0')
>
>         Map connectionMap = *buildConnectionMap*(map)
>
>         *log*.info "connecting to [${connectionMap.url}] as [${
> connectionMap.user}]"
>
>         Sql sql = Sql.*newInstance*(connectionMap)
>
>         sql.connection.setAutoCommit(*false*)
>
>         sql
>
>     }
>
>
>
> In my Oracle class.
>

Mime
View raw message