How to add ojdbc7 to Java web app by Gradle?

狂风中的少年 提交于 2019-11-29 07:15:49
Robin A. Meade

Gradle currently can't handle the redirects needed by the realm-based SSO mechanism used by Oracle's maven repo.

A workaround is to use this URL instead

url "https://www.oracle.com/content/secure/maven/content"

In addition, you need to supply credentials for authentication.

Here's a minimal example:

plugins {
  id 'java'
}

repositories {
    jcenter()

    maven {

       url "https://www.oracle.com/content/secure/maven/content"

       credentials {
         username = '<Oracle Account email address>'
         password = '<Oracle Account password>'
       }
    }
}

dependencies {
    compile 'com.oracle.jdbc:ojdbc7:12.1.0.2'
}

I have a github repo with full example including a way of encrypting the password using maven's settings.xml and settings-security.xml: example-gradle-oracle

I am adding = after username and password as mentioned in Gradle AuthenticationSupported.java file

Your build.gradle will work if you replace:

maven {
    url ("https://maven.oracle.com")
}

to:

maven {
    url "https://www.oracle.com/content/secure/maven/content"
    name "maven.oracle.com"
    credentials {
       username 'email@mail.com'
       password 'your password'
    }
}

Credetials from Oracle Registration page: https://profile.oracle.com/myprofile/account/create-account.jspx.

Additionally:

To place authentication data outside of project home, you can edit configuration file ~/.gradle/gradle.properties:

mavenOracleUsername=email@mail.com
mavenOraclePassword=your password

and use it in configuration like:

 credentials {
    username mavenOracleUsername
    password mavenOraclePassword
}

For Oracle database 12c

(1) Download ojdbc7.jar at Oracle homepage.

(2) Run command

mvn install:install-file -Dfile=ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.1 -Dpackaging=jar

(3) Add to build.gradle

compile('com.oracle:ojdbc7:12.1.0.1')

I've added the http://nexus.saas.hand-china.com/content/repositories/rdc/ repo and work

repositories {
    mavenCentral()
    //Add this repo
    maven {
        url "http://nexus.saas.hand-china.com/content/repositories/rdc/"
    }
}
...
dependencies {
   ....
   compile group: 'com.oracle', name: 'ojdbc7', version: '12.1.0.2'
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!