How to use Oracle JDBC driver in Gradle project

I am new to Gradle projects and I have one question. I searched the Internet, but I could not find what I needed, or maybe I did not know how to look for it. First, I will tell you my business. I have a Gradle project and I would like to run some automated tests in the future with jenkins, but now I want to try Eclipse. I have oracle jdbc driver in / lib directory and this is my build.gradle

apply plugin: 'java' // In this section you declare where to find the dependencies of your project repositories { jcenter() //mavenCentral() } // In this section you declare the dependencies for your production and test code dependencies { compile 'org.slf4j:slf4j-api:1.7.21' compile 'org.seleniumhq.selenium:selenium-java:2.+' compile 'org.testng:testng:6.+' //compile 'com.oracle:ojdbc14:10.2.0.4.0' //testCompile 'net.sourceforge.jexcelapi:jxl:2.6.12' testCompile 'info.cukes:cucumber-core:1.+' testCompile 'info.cukes:cucumber-java:1.+' testCompile 'info.cukes:cucumber-junit:1.+' testCompile 'junit:junit:4.12' } repositories { flatDir(dir: 'libs')//, name: 'Local libs' } dependencies { compile name: 'ojdbc7' } 

I would like to use this jdbc driver in one class, but I don't know how to use it. When I tried with Maven, I used this method "import oracle.jdbc.driver.OracleDriver;" but I think this is not valid for the Gradle project. could you help me? thanks in advance

+14
jdbc ojdbc build.gradle gradle
source share
5 answers

You can simply add the jar as a dependency, for example:

 compile files('libs/ojdbc7.jar') 

And there is no need to add the flatDir repository in this case. Read about it in the official guide.

+18
source share

You can try reusing the local Maven repository for Gradle:

  • Download ojdbc7.jar from Oracle website
  • Install the jar in the local Maven repository:

     mvn install:install-file -Dfile=ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.1 -Dpackaging=jar 
  • Make sure you have the bank installed in the local repository ~/.m2/

  • Include the local Maven repository in the build.gradle file:

     repositories { mavenCentral() mavenLocal() } dependencies { compile ("com.oracle:ojdbc7:12.1.0.1") } 
  • Now you need to enable the jar to compile in your project

+19
source share

In addition to the correct answer, I want to share my experience in solving the ojdbs dependency problem (using gradle and Intellij Idea).

  1. Go to the oracle site and upload the jdbs files. I decided to download the full archive - ojdbc8-full.tar.gz
  2. Unzip the archive into someone’s directory (for example, c: \ folder \ OJDBC8-Full)
  3. In Intellij Idea, go to Project / Library Structure, click the β€œ+” symbol and specify the path to the folder into which the archive is unpacked (OJDBC8-Full). Enter a name:

enter image description here

  1. In build.gradle add:

dependencies {

...

compilation files ('libs / OJDBC8-Full') // OJDBC8-Full is the name you specify for librare

...

}

+2
source share

Since SSO-based authentication is not available in gradle:

You currently have 3 options:

(+ 1 use maven)

see https://discuss.gradle.org/t/support-for-maven-repositories-that-use-realm-based-sso/14456

0
source share

besides mavenCentral use the local maven repository for our dependencies. The reason for using the local maven repository is that the jdbc driver from Oracle is not publicly available. We will need to download the driver from Oracle and install it in our local Maven repository.

 repositories { mavenLocal() } dependencies { compile ("com.oracle:ojdbc6:12.2.0.1") } mvn install:install-file -Dfile="\ojdbc6.jar" -DgroupId="com.oracle" -DartifactId="ojdbc6" -Dversion="12.2.0.1" -Dpackaging="jar" -DgeneratePom="true" 

Oracle site for driver:

https://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html

Maven website:

https://maven.apache.org/download.cgi

0
source share

All Articles