简体   繁体   中英

How to add ojdbc7 to Java web app by Gradle?

My context:

  • I build a Java web application what based on Spring Boot 1.3.5.RELEASE .
  • I try to add ojdcb to dependencies list but not success.
  • I know that Oracle has own Maven repository at http://maven.oracle.com

This is my build.gradle file, Let focus at line 4, 5, 6, 36:

buildscript {
    repositories {
        mavenCentral()
        maven {
            url ("https://maven.oracle.com")
        }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.5.RELEASE")

    }
}

apply plugin: 'war'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
    baseName = 'erp'
    version = '1.0.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    //compile("org.springframework.boot:spring-boot-starter-security")
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.hibernate:hibernate-core")
    compile("com.oracle.jdbc:ojdbc7:12.1.0.2")
    testCompile("junit:junit")
}

IntelliJ IDEA 2016 notice error:

Warning: Details: org.gradle.api.artifacts.ResolveException: Could not resolve all dependencies for configuration ':runtime'. 详细信息:org.gradle.api.artifacts.ResolveException:无法解析配置':runtime'的所有依赖项。 Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find com.oracle.jdbc:ojdbc7:12.1.0.2. Required by: :erp:unspecified

在此输入图像描述

(Related links: http://docs.oracle.com/middleware/1213/core/MAVEN/config_maven_repo.htm#MAVEN9015 https://blogs.oracle.com/dev2dev/entry/how_to_get_oracle_jdbc https://blogs.oracle.com/dev2dev/entry/oracle_maven_repository_instructions_for )

Help me add ojdbc to dependencies list by Gradle, thank you!

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'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM