How to add ojdbc7 to Java web app by Gradle?

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 protected]'
       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:

[email protected]
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')