How to use Oracle JDBC driver in Gradle project

前端 未结 7 1184
醉话见心
醉话见心 2020-12-15 19:09

I\'m new with Gradle projects and I have one question. I\'ve searched in Internet but I couldn\'t find what I need or maybe I couldn\'t know how to search it. First I\'m goi

相关标签:
7条回答
  • 2020-12-15 19:34
    repositories {
       flatDir { dirs "libs" }
       }
       dependencies {
         compile files( 'libs/ojdbc-16.jar')
       }
    

    create "libs" directory under project root and put that into it.

    0 讨论(0)
  • 2020-12-15 19:36

    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

    ...

    }

    0 讨论(0)
  • 2020-12-15 19:39

    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

    0 讨论(0)
  • 2020-12-15 19:41

    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

    0 讨论(0)
  • 2020-12-15 19:42

    Since SSO-based authentications are not available in gradle:

    Currently you have 3 alternatives:

    • download manually and copy the file (see above)
    • use a proxy to authenticate (and register an account for oracle maven repo)
    • if you have an internal repository: you can use your repo to proxy/cache oracle's one (e.g.: Nexus Oracle settings: https://support.sonatype.com/hc/en-us/articles/213465728-How-to-configure-a-proxy-repository-to-maven-oracle-com)

    (+1 use maven)

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

    0 讨论(0)
  • 2020-12-15 19:47

    Time is 2019 and Oracle finally decided to let "Maven Central becomes a distribution center for the Oracle JDBC drivers".

    For example, if you want to use OJDBC version 19 with Java 8, you can find ojdbc jar in Maven Central. Please be aware there is a typo in group name. It should have been com.oracle.ojdbc instead of com.oracle.jdbc

     repositories {
        mavenCentral()
    }
    
    dependencies {
        compile "com.oracle.ojdbc:ojdbc8:19.3.0.0"
    }
    
    0 讨论(0)
提交回复
热议问题