groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nelson, Erick" <>
Subject Re: Convert @Grab to Grape.grab ?
Date Mon, 20 Jan 2020 22:46:33 GMT
Ya, ive tried that, it’s the grabconfig systemClassLoader=true  that is making this difficult
for me (I think).
I get the usual error as if I did not put the grab config in the @grab annotation …

java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@//

I’m still going through groovy.grape.GrabAnnotationTransformation to see how it is done

Erick Nelson
Senior Developer – IT
HD Supply Facilities Maintenance
(858) 740-6523

From: Paul King <>
Reply-To: "" <>, ""
Date: Monday, January 20, 2020 at 2:32 PM
To: "" <>
Subject: Re: Convert @Grab to Grape.grab ?

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

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

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 <<>>
Is it possible to convert a Grab annotation to a Grapes.grab call?

Convert this…

import groovy.sql.Sql

to this…

groovy.grape.Grape.grab(group:'', module:'ojdbc6', version:'')

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:'', module:'ojdbc6', version:'')

        Map connectionMap = buildConnectionMap(map) "connecting to [${connectionMap.url}] as [${connectionMap.user}]"

        Sql sql = Sql.newInstance(connectionMap)




In my Oracle class.
View raw message