How to use Oracle JDBC driver in Gradle project

雨燕双飞 提交于 2019-11-29 03:27:51

You can simply add a jar as dependency, like so:

compile files('libs/ojdbc7.jar')

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

Daniel Mora

You can try reusing your local Maven repository for Gradle:

  • Download ojdbc7.jar from Oracle site
  • Install the jar into your local Maven repository:

    mvn install:install-file -Dfile=ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.1 -Dpackaging=jar
    
  • Check that you have the jar installed into your ~/.m2/ local Maven repository

  • Enable your local Maven repository in your build.gradle file:

    repositories {  
        mavenCentral()  
        mavenLocal()  
    }  
    
    dependencies {  
        compile ("com.oracle:ojdbc7:12.1.0.1")  
    }  
    
  • Now you should have the jar enabled for compilation in your project

In addition to correct answer, I want to share my experience how I solve a problem with ojdbs dependence (used gradle and Intellij Idea).

  1. Go to the oracle site and download jdbs file(s). I chose to download the full archive - ojdbc8-full.tar.gz
  2. Unpack the archive in someone directory (for example c:\folder\OJDBC8-Full)
  3. In Intellij Idea go to the Project Structure/Libraries, press "+" symbol and specify a path to the folder there archive unpacked (OJDBC8-Full). Specify name:

  1. In build.gradle add:

dependencies {

...

compile files('libs/OJDBC8-Full') //OJDBC8-Full - it is name what you specify for librare

...

}

Since SSO-based authentications are not available in gradle:

Currently you have 3 alternatives:

(+1 use maven)

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

aravind s

other than mavenCentral use local maven repository as well for our dependencies. The reason for using the local maven repository is because the jdbc driver from Oracle is not publicly accessible. We will have to download the driver from Oracle and install it in our local maven repo.

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 site:

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!