Gradle - Ant - third party driver


(Chris Madison) #1

Hi,

I have an ant build file (build.xml) with a sql task.

<sql driver=“org.netezza.Driver”

url=

and so on

The jar file for the driver is available in standard network location, say, S:\JDBC

Now if I want to call the SQL task from Gradle, I’m trying to do

in my build.gradle

ant.importBuild(‘build.xml’)

gradle db

Execution failed for task ‘:db’. Cause: Class Not Found: JDBC driver org.netezza.Driver could not be loaded Cause: org.netezza.Driver

How can I make gradle load the their party jar file?

I tried several things suggested like.

buildscript {

repositories {

flatDir(name: ‘driver’, dirs: “S:/JDBC”)

}

dependencies {

classpath name: ‘nzjdbc’

} }

  1. Copied the jar file to lib directory of gradle.

  2. http://stackoverflow.com/questions/6329872/how-to-add-external-jar-files-to-gradle-build-script

  3. buildscript {

repositories {

flatDir(name: ‘driver’, dirs: “C:/JDBC”)

}

dependencies {

classpath name: ‘nzjdbc’

} }

  1. Few other things i found online, like using groovy class loader.

Nothing seems to be working, any help is highly appreciated.


(Szczepan Faber) #2

Hey, can you be more specific with the question? :slight_smile:


(Chris Madison) #3

Sorry, this is strange, I had a whole message typed up and for some reason only 1 line showed up. (may be i didn’t confirm email before posting)

Here is it again.

I need to execute an ant target from within gradle and here is simplified example of what I’m trying to do.

build.xml -

<sql driver=“org.netezza.Driver”

url=“jdbc:netezza://${server}:${port}/${db}”

userid="${user}"

password="${passwd}"

print=“true”>

select now();

build.gradle

buildscript {

repositories {

flatDir(name: ‘driver’, dirs: “S:/JDBC”)

}

dependencies {

classpath name: ‘nzjdbc’

} }

ant.importBuild(‘build.xml’)

— Now when I try to do

gradle db

I get the following message.

Cause: Class Not Found: JDBC driver org.netezza.Driver could not be loaded Cause: org.netezza.Driver

I tried various things like

  1. Copying the driver jar file to gradle lib directory - didn’t help

  2. Tried various suggestions after searching online.

Example:

http://stackoverflow.com/questions/6329872/how-to-add-external-jar-files-to-gradle-build-script http://gradle.1045684.n5.nabble.com/How-to-use-class-from-external-Jar-td1434333.html

  1. Tried suggested method under file management section http://www.gradle.org/dependency_management

  2. Tried using classloader example i found online.

Class driverClass = loader.loadClass(‘org.netezza.Driver’)

configurations {

driver }

repositories {

flatDir name: ‘localRepository’, dirs: ‘lib’ }

dependencies {

driver name: ‘nzjdbc’ }

configurations.driver.each {

File file ->

loader.addURL(file.toURL())

}

Nothing works. I think i’m missing something very basic here. Any help is highly appreciated.


(Chris Madison) #4

Forgot to mention, to run it from ant, all i had to do is put jdbc.jar file CLASSPATH env and it works fine.

At a later point I would like to point gradle to different places where a whole bunch of jar files are located that are needed to run various ant tasks.