I needed to download Oracle JDBC jar files for use with my database query tool. Oracle JDBC drivers have been available in the public official Maven repository since September 15, 2019. They extended it to include all supported releases in February, 2020. (link1 link2 link3 link4).
It is possible to automate the download of these jars using maven
. You can
download the latest version, or a specific version.
See the example download-ojdbc.xml
file below. It downloads the latest Oracle
jdbc jar files and copies them to the appropriate directory (~/.dbvis/jdbc
,
in my case).
It utilizes the copy goal of the Apache Maven Dependency Plugin. Consult the documentation for the various parameters you may use.
Note that I bound the execution of the copy
goal to the validate
phase,
and I specified the validate
phase as the default phase using the defaultGoal
element. (The defaultGoal
element takes either a goal or a phase).
This let's me execute it simply as:
mvn -f download-ojdbc.xml
instead of
mvn -f download-ojdbc.xml dependency:copy@theExecutionId
The later would have required adding id
element too, like this:
<id>theExecutionId</id>
Partial output:
[INFO] com.oracle.database.jdbc:ojdbc8:LATEST:jar already exists in /home/robin/.dbvis/jdbc
[INFO] com.oracle.database.nls:orai18n:LATEST:jar already exists in /home/robin/.dbvis/jdbc
[INFO] com.oracle.database.xml:xmlparserv2:LATEST:jar already exists in /home/robin/.dbvis/jdbc
[INFO] com.oracle.database.xml:xdb:LATEST:jar already exists in /home/robin/.dbvis/jdbc
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.863 s
[INFO] Finished at: 2020-12-22T13:20:19-10:00
[INFO] ------------------------------------------------------------------------
A nice thing about this is that it is idempotent. As you see in the above output, it detected that the latest jar files were already present and didn't overwrite them. (This behavior can be changed with parameters of the copy goal.)
I also like how maven embeds the version in the filename, e.g.,
ojdbc8-19.8.0.0.jar
. That wouldn't be the case if I downloaded the drivers
directly from
https://www.oracle.com/database/technologies/jdbc-upc-downloads.html.