403 Forbidden for jdbc driver from Oracle reposito

2019-08-06 04:17发布

问题:

I want to download the odjbc7.jar at compile time so that I can run all of my tests in Travis CI. I've added a setting in my gradle.properties so that it'll only download the jar for building.

Users of my tool will provide the driver themselves so as not to go against Oracles license agreements.

All of the solutions I have found online answer the question by saying to point to a local jar which won't work for my CI build or for others wanting to build the application (I can't distribute the ojdbc jar as part of my repository).

Below is the relevant sections of my build.gradle, I have the properties mavenOracleUsername and mavenOraclePassword in my gradle.properties (I have checked these are correct on the Oracle single-sign on site) :

def oracleUsername = hasProperty('mavenOracleUsername') ? mavenOracleUsername : System.getenv('mavenOracleUsername')
def oraclePassword = hasProperty('mavenOraclePassword') ? mavenOraclePassword : System.getenv('mavenOraclePassword')

repositories {
    jcenter()

    maven {
        url "https://www.oracle.com/content/secure/maven/content"
//        url "https://maven.oracle.com"
        credentials {
            username "${oracleUsername}"
            password "${oraclePassword}"
        }
    }
}

...

dependencies {
    compile group: 'com.oracle.jdbc', name: 'ojdbc7', version: '12.1.0.2'
}

When I run my build I get the following error:

Could not resolve all dependencies for configuration ':compileClasspath'.
> Could not resolve com.oracle.jdbc:ojdbc7:12.1.0.2.
  Required by:
      project :
   > Could not resolve com.oracle.jdbc:ojdbc7:12.1.0.2.
      > Could not get resource 'https://www.oracle.com/content/secure/maven/content/com/oracle/jdbc/ojdbc7/12.1.0.2/ojdbc7-12.1.0.2.pom'.
         > Could not GET 'https://www.oracle.com/content/secure/maven/content/com/oracle/jdbc/ojdbc7/12.1.0.2/ojdbc7-12.1.0.2.pom'. Received status code 403 from server: Forbidden

If I change the credentials I get a 401 response and if I change the version of the jar I get a not found in repository error.

回答1:

I found the solution to be to upgrade the version of the driver to ojdbc8.

This link helped:

https://blogs.oracle.com/dev2dev/get-oracle-jdbc-drivers-and-ucp-from-oracle-maven-repository-without-ides

My build.gradle now looks like:

def oracleUsername = hasProperty('mavenOracleUsername') ? mavenOracleUsername : System.getenv('mavenOracleUsername')
def oraclePassword = hasProperty('mavenOraclePassword') ? mavenOraclePassword : System.getenv('mavenOraclePassword')

repositories {
    jcenter()

    maven {
        url "https://www.oracle.com/content/secure/maven/content"
//        url "https://maven.oracle.com"
        credentials {
            username "${oracleUsername}"
            password "${oraclePassword}"
        }
    }
}

...


dependencies {
    compile group: 'com.oracle.jdbc', name: 'ojdbc8', version: '12.2.0.1'
}

I have also documented an issue I raised on a tutorial GitHub repository:

https://github.com/robin-a-meade/example-gradle-oracle/issues/1

Edit: Any issue arose with this dependency, so I had to change to this:

compile(group: 'com.oracle.jdbc', name: 'ojdbc8', version: '12.2.0.1') {
    exclude module: 'xmlparserv2'
}

For an explanantion of why this is needed, see here this question: Is "xmlparserv2" from "com.oracle.jdbc:ojdbc8" (v12.2.0.1) all of a sudden corrupt?