utPLSQL / utPLSQL-maven-plugin

Maven plugin for running Unit Tests with utPLSQL v3
Apache License 2.0
13 stars 11 forks source link

No suitable driver found for jdbc:oracle:thin: ... #23

Closed georgy closed 5 years ago

georgy commented 6 years ago

I have a bit of a problem running utPLSQL-maven-plugin. If I simply add the plugin

org.utplsql utplsql-maven-plugin 3.1.0-SNAPSHOT ...

Then I get following error:

Caused by: java.lang.ClassNotFoundException: oracle.sql.ORAData

This makes me think I need to add oracle jdbc driver onto classpath of the plugin. So I added the dependencies:

org.utplsql utplsql-maven-plugin 3.1.0-SNAPSHOT
                      <dependencies>
                        <dependency>
                          <groupId>com.oracle.jdbc</groupId>
                          <artifactId>ojdbc8</artifactId>
                          <version>12.2.0.1</version>
                        </dependency>
                        <dependency>
                          <groupId>com.oracle.jdbc</groupId>
                          <artifactId>orai18n</artifactId>
                          <version>12.2.0.1</version>
                        </dependency>
                      </dependencies>

That helps a bit, but the test run still fails with

Caused by: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin: ...

I can't find where in the code (plugin or java-api) do you register the oracle driver class. I can see that in cli project there is Class.forName(), but nothing like it in plugin nor java-api.

What is the right way to register the driver then?

jgarec commented 6 years ago

Hi,

Exactly the same as #11.

I think it's related to the jdk. JDBC Spec says that the driver should be registred automatically...

georgy commented 6 years ago

Which part of JDBC spec?

On Fri, 20 Jul 2018 at 15:52, jgarec notifications@github.com wrote:

Hi,

Exactly the same as #11 https://github.com/utPLSQL/utPLSQL-maven-plugin/issues/11.

I think it's related to the jdk. JDBC Spec says that the driver should be registred automatically...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/utPLSQL/utPLSQL-maven-plugin/issues/23#issuecomment-406606971, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGA6eWSMiyyS5McnOfJ8ySG4DMwJcgaks5uIeCUgaJpZM4VYDpo .

georgy commented 6 years ago

I am guessing you mean the service provider mentioned in: https://docs.oracle.com/javase/6/docs/api/java/sql/DriverManager.html

jgarec commented 6 years ago

Yes.

jgarec commented 6 years ago

I don't remember how i solved this problem on my windows computer at work. I was not able to reproduce on my mac.

Which OS ? How do you get ojdbc ? from Oracle maven repository ? you install it locally ? Which JRE ?

You're running maven through eclipse or with command line ?

alberto-hernandez commented 6 years ago

Hi @georgy,

All Oracle components are NOT published in the public repositories (maven central, etc) so you need to downloaded and imported to your local maven repository.

Could you check if you have it? If not, please try to download them and installed in your repository.

georgy commented 6 years ago

@alberto-hernandez the dependency comes from company's internal maven repo. I add the jar to the plugins classpath by adding dependency to the plugin configuration (described in my original message).

@jgarec Win 7, JDK 8, dependency comes from company's internal maven repo. I am running maven from the command line.

I will try to debug this a bit, from looking at the source code and environment is should work.

jgebal commented 6 years ago

@georgy Is this issue still valid or can it be closed?

jgebal commented 6 years ago

Closing as no response from @georgy

hinjo89 commented 5 years ago

Hi, I'm trying to get this maven plugin to work, but I'm encountering the same problem 'no suitable driver found for jdbc:oracle:thin:[...]'.

Since this problem was discussed in this Issue, but not resolved as far as I can see it, I'm posting here. If I should rather open a new ticket I can also do that.

Maven is executed with a jdk 8 (1.8.0_192) and the maven dependencies come from a company internal maven repository. Since the utplsql java api is listing all the oracle dependencies in its POM and maven is not complaining about not finding dependencies I figure that the dependencies should be satisfied...

Did you guys find some way to get this work in the meantime? In other tools running with the same maven repository and the same DB connection string the database access is working fine.

Thanks, Johannes

jgarec commented 5 years ago

I reopen this issue as it's the third time someone talk about this... But it's really hard to reproduce ...

Could you provide your pom file ? try to remove all unnecessary parts

jgebal commented 5 years ago

I got it working from a private repo at work (with no access to public repo). Will provide example config and requirements.

jgebal commented 5 years ago

utplsql-maven-plugin is build without it's dependencies. In order for it to work from your private repo, when you have no access to internet, you need to have the following modules in your private repo available:

Group: org.utplsql
Artifact: utplsql-maven-plugin
Version: 3.1.2
---
Group: org.utplsql
Artifact: java-api
Version: 3.1.2
---
Group: com.oracle.jdbc
Artifact: ojdbc8
Version: 12.2.0.1

Additionally, in your pom configuration, you need to specify dependency to ojdbc driver.

Here is example extract of config that works for me:

            <plugin>
                <groupId>org.utplsql</groupId>
                <artifactId>utplsql-maven-plugin</artifactId>
                <version>3.1.2</version>
                <configuration>
                    <reporters>
                        <reporter>
                            <name>ut_documentation_reporter</name>
                            <consoleOutput>true</consoleOutput>
                        </reporter>
                        <reporter>
                            <name>ut_junit_reporter</name>
                            <fileOutput>junit_test_results.xml</fileOutput>
                        </reporter>
                        <reporter>
                            <name>ut_coverage_cobertura_reporter</name>
                            <fileOutput>cobertura_coverage.xml</fileOutput>
                        </reporter>
                    </reporters>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.oracle.jdbc</groupId>
                        <artifactId>ojdbc8</artifactId>
                        <version>12.2.0.1</version>
                        <scope>compile</scope>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

@jgarec, @viniciusam Can we have java-api packaged with maven plugin? That way, users don't need to pull needed package manually into their private (enterprise) repo.

I know we can't package ojdbc due to licensing.

@hinjo89 - the utplsql-api is published to https://packagecloud.io/utPLSQL/utPLSQL-java-api

hinjo89 commented 5 years ago

Hi,

we have utplsql-maven-plugin with jar and pom and also java-api with jar and pom and all their respective dependencies in our enterprise (nexus) repo.

So ojdbc8 12.2.0.1 is already resolved via the java-api dependencies and maven would fail much earlier if this would not be available.

But just to be sure I also tried to put ojdbc8 explicitly into the plugin dependencies, I also tried to put it everywhere else, but it still ends up with the same error message every time.

Here the relevant part of my pom.xml (with the dependency, even though that shouldn't make a difference):

<plugin>
                <groupId>org.utplsql</groupId>
                <artifactId>utplsql-maven-plugin</artifactId>
                <version>3.1.2</version>
                <dependencies>
                    <dependency>
                        <groupId>com.oracle.jdbc</groupId>
                        <artifactId>ojdbc8</artifactId>
                        <version>12.2.0.1</version>
                        <scope>compile</scope>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <paths>
                                <path>...</path>
                            </paths>

                            <reporters>
                                ...
                            </reporters>

                        </configuration>
                    </execution>
                </executions>
            </plugin>

So all in all I'm very sure that ojdbc is on my classpath sot that I'm left wondering why the driver is not found. I've also tried it with two different java 8 jdks that I have availble, but same behaviour... Maybe it would make sense to add an optional dbDriver property to be able to explicitly initialize the db driver.

Thanks, Johannes

hinjo89 commented 5 years ago

Hi Georgy,

why did you close this again? I don't have a solution yet. How did you solve this before?

Thanks, Johannes

georgy commented 5 years ago

Sorry, I was writing a comment and probably clicked close by mistake :). We ended up implementing a workaround, but as far as the issue goes: root cause is still unclear. The last thing that we saw was that JDK code responsible for service discovery runs twice: the first time it finds correct config file on classpath, but when it runs second time it does not find the service definition in ojdbc jar. It looks like results of the first lookup are ignored (since the driver class is not loaded), but that is all we know right now.

This problem nags me a little bit from the back of my mind, but not enough for me to invest my time :). Not yet at least. The main complication is that the issue only reproducible on some setups and I was not able to get the repro on my environments. So the only viable solution for me is to grab a laptop from a colleague that has this issue and run away for a couple of hours. Not everyone appreciates that approach.

viniciusam commented 5 years ago

@jgebal sorry for the late reply. I believe we can embed the java-api code into the maven-plugin's code without any problems. Let me try to sort this out this week.

I'm not sure if there's much we can do about the oracle driver, maybe if we embed and shade the library paths we won't be violating any licenses, I can try doing it and then we can avail if it would be an issue.

pesse commented 5 years ago

If we embed the java-api code we should make sure it's an automatic process to keep up-to-date.

Oracle driver may not be embedded or we will break license rules (there was a lengthy thread in the slack-group by Gerarld Venzl)

hinjo89 commented 5 years ago

Hi,

sorry for the late reply, but I can't imagine that this would fix the problem, since the issue is not that the java-api and its dependencies are not on the classpath. All of them including java-api and ojdbc are on our company maven repository, so they are there.

I will try to build the referenced pull request one of these days to test it.

Thanks, Johannes

alesana-san commented 5 years ago

Hey guys! It's +1 to ones who get that error. I'm using maven to build a project so when it comes to testing it fails with No suitable driver. I tried the solution @jgebal described but didn't succeed. Putting driver everywhere in pm.xml doesn't make any difference.

jgebal commented 5 years ago

We probably need more info on this issue. What version of java are you using? What version of maven? What is the exact stackrace?

alesana-san commented 5 years ago

@jgebal

hinjo89 commented 5 years ago

Hi, when I tried it last time, I tried multiple Java versions and also multiple maven versions. Always the same issue. I gave it up after a while, but would also still be interested in case the root would be found.

adrianhj commented 5 years ago

Running into a similar issue.

When running liquibase-maven-plugin to set-up the database, followed by utplsql-maven-plugin to execute tests -- liquibase would run in fine and utPLSQL would crash on missing classes.

Swapping the DriverManager to DataSource as per https://github.com/adrianhj/utPLSQL-maven-plugin/commit/4a23f0c4851c2c3d290681831a503147d8a01936 seems to have resolved our issue from a quick test at least (as in it now runs liquibase maven plugin, followed by utPLSQL maven plugin OK).

pesse commented 5 years ago

Thank you very much, @adrianhj I guess we should be easily able to get rid of the DriverManager for utPLSQL doesn't really need a ConnectionPool anyway. We plan to outsource that whole part to java-api, too, so maven-plugin and cli will be more similar.

alesana-san commented 5 years ago

Actually I haven't tried running tests without liquibase. Will try it as @adrianhj told

alesana-san commented 5 years ago

It was kinda silly of me not to try mvn clean compile test -P profile - it works well inside my air-gapped system. The problem really comes up when you run it like mvn clean compile liquibase:update test .... Maybe it somehow messes up with drivers or something.

adrianhj commented 5 years ago

I had the chance to debug a bit further today so as to understand the root cause for the Liquibase + utPLSQL combination issue.

What seems to happen is the following:

I believe there are two options:

  1. Retrieve and set-up an instance of the oracle.jdbc.driver.OracleDriver directly same as Liquibase, not going through the DriverManager.
  2. Replace DriverManager with an OracleDataSource

I will open a PR for option 2 as I don't believe there is a strong need to remain DB agnostic here unless anyone believes otherwise.. :-)

pesse commented 5 years ago

Thanks a lot for your thorough investigation - and no, we really don't need DB agnostic approach for utPLSQL plugin ;)

jgebal commented 5 years ago

The issues should now be resolved by #44

preethileela commented 4 years ago

How does this is resolved. I am facing same issue

alesana-san commented 4 years ago

@preethileela have you tried the latest version of CLI? AFAIK the solution was merge into the project.

preethileela commented 4 years ago

It's working fine now cool

getshravan commented 4 years ago

when utPLSQL-maven-plugin 3.1.3 release version made available with this change ? I am still seeing 3.1.3-SNAPSHOT version