Using Sqlite JDBC Driver in a Gradle Java Project - java

In this tutorial, http://www.sqlitetutorial.net/sqlite-java/sqlite-jdbc-driver/, about using sqlite with java, it starts by downloading the JDBC driver from the following website, https://bitbucket.org/xerial/sqlite-jdbc/downloads/. After that it then adds the driver to the project using a Maven build system.
I have had a look around and I cannot see what you should if you are using Gradle? What steps should you take before you the code?
I am using the Intellij IDE if this makes any difference.

Sqlite JDBC driver is available in Maven Central Repository: SQLite JDBC
So in Gradle you can add this dependency in your build.gradle as follows:
repositories {
mavenCentral()
}
dependencies {
compile group:'org.xerial', name:'sqlite-jdbc', version:'3.8.11.2'
}
Or in a Maven project in your pom.xml file:
<dependencies>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.8.11.2</version>
</dependency>
</dependencies>

The Gradle syntax has changed as of version 3.4. So according to new syntax add the following to your build.gradle file:
repositories {
mavenCentral()
}
dependencies {
implementation 'org.xerial:sqlite-jdbc:3.30.1'
}

Related

How to use ojdbc with Gradle

I'm new to Gradle so I have awfully big problems and one of them is about the Oracle JDBC driver. I just want to get connection to DB and I already used a JDBC driver in my previous project, but that did not use Gradle. Now, I see that I have to show dependency on driver, but this just didn't work. I already used all of the advice I found:
I tried to add connector.jar to VM options,
to create dependency with implementation("com.oracle.database.jdbc:ojdbc8:21.1.0.0"), but it simply doesn't work.
After I use compile 'com.oracle:ojdbc8:21.1.0.0', I got Could not find method compile() for arguments [com.oracle:ojdbc8:21.1.0.0] and that's just killing me.
I also tried to use local Maven repository and I have downloaded .jar, but it doesn't work either.
I also just tried to add this lib dependency in IntelliJ, using File->Project Structure->+ and creating ojdbc8 class with path to this file directly.
Full version of my build.gradle file:
plugins {
// Apply the application plugin to add support for building a CLI application in
Java.id 'application'
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
mavenLocal()
}
dependencies {
implementation("com.oracle.database.jdbc:ojdbc8:21.1.0.0")
compile 'com.oracle:ojdbc8:21.1.0.0'
// Use JUnit test framework.
testImplementation 'junit:junit:4.13.2'
implementation 'com.h2database:h2:1.4.199'
implementation 'org.hibernate:hibernate-core:5.4.2.Final'
// This dependency is used by the application.
implementation 'com.google.guava:guava:30.1.1-jre'
}
application {
mainClass = 'model.App'
}
I'd like to use this JDBC driver in one class, but I just can't. Can you help me, please?

Gradle find wrong maven repository url in eclipse

this is my build.gradle
repositories {
mavenCentral()
maven{url 'http://example.com/repository/maven-public/'}
}
dependencies {
compile group: 'com.example', name: 'example-commlib', version: '1.0'
}
and the link http://example.com/repository/maven-public/ is build from Nexus Repository Manager which can accessable.
and when I click Refresh Gradle Project in eclipse.
I can see the link is point to
https://repo.maven.apache.org/..../example-commlib-1.0.pom
I think the right url is
http://example.com/repository/maven-public/.../example-commlib-1.0.pom
I've check the gradle setting and maven setting in eclipse. It seems fine.
So what's the problem?
Do you have other dependencies on this project? It is possible that the "pom.xml" file of one of the packages you are pulling references example-commlib as a dependency and has the Apache Maven URL hardcoded, and resolves the URL beforehand. You can use gradle dependencies to show the dependency tree and find which version is affected. The answers in this post have suggestions on how to force a specific dependency as well: How can I force Gradle to set the same version for two dependencies?

Unable to use gradle plugin from local Nexus repository

I am trying to use the grgit plugin from within my gradle script. I have a file that is modified by our CI server during build and I want this to be committed to out git repo as part of the build process.
I have a local Nexus repo which has a proxy to maven central. How do i get access to the gradle plugin via my Nexus repo? Currently, I have:
buildscript {
repositories {
maven {
url "http://my-nexus:6666/nexus/content/groups/public/"
}
}
dependencies {
classpath "org.ajoberstar:grgit:1.7.2"
}
}
apply plugin: "org.ajoberstar.grgit"
This downloads the dependency from Nexus, but results in > Plugin with id 'org.ajoberstar.grgit' not found. when doing a gradle build.
I have read the documentation regarding custom plugin repositories but prefer the old method rather than the DSL method because I have hundreds of projects and don't want to define the repository in every settings.gradle file since at the moment, pluginRepositories can only be specified in the settings.gradle file.
How can I get the apply plugin method to work?
That's because the version of the Grgit library you use does not have the Gradle plugin included. Only newer versions, that are not in maven central nor jcenter (only in Gradle plugins repository).
You have two ways to fix it
a) Change the library:
buildscript {
repositories {
maven {
url "http://my-nexus:6666/nexus/content/groups/public/"
}
}
dependencies {
classpath "org.ajoberstar:gradle-git:1.7.2"
}
}
apply plugin: "org.ajoberstar.grgit"
b) Mirror the gradle-plugins repository in your local Nexus repo from
https://plugins.gradle.org/m2/ and version of 2.1.1 grgit

How to import maven into my Android Studio project?

There is a library that I would like to use for my Android App: ez Vcard. However this library uses Maven, which I'm not familiar with. I checked online and my Import Project objection doesn't offer pom.xml soo, how can I add the dependency
<dependency>
<groupId>com.googlecode.ez-vcard</groupId>
<artifactId>ez-vcard</artifactId>
<version>0.9.9</version>
</dependency>
into my project and specifically where?
You don't need a maven project, you can use maven dependencies in gradle projects, you'll just have to use a gradle format of the dependency.
This library appears to be hosted on maven central, so you have to link to this repository host in your global build.gradle:
allprojects {
repositories {
mavenCentral()
}
}
To import this dependency into your project, in your module-local build.gradle file input the following lines:
dependencies {
compile 'com.googlecode.ez-vcard:ez-vcard:0.9.9'
// all the other dependencies...
}
You can actually see here all the different dependency formats (under 'Dependency Information'), from maven to gradle, ivy, sbt and so on, they are all compatible with the repository.

How to configure maven in android stuio?

i had been using eclipse .it was fine with m2 plugin.now i switched to android studio.i dont know how to convert my project to maven project.Any help would be appreciated?
P.s I installed maven in my windows 7. in build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.0'
}
}
mavenCentral() is the central repository shorthand, it's like this tag in the pom.xml.
build.gradle is a Gradle build system build file, to convert to Maven build system you need a pom.xml.
I suggest you import your existing project (which has the pom.xml) view File > Import Project... and select Maven during the import.
Google's suggested way of building Android apps is with Android Studio, which tightly integrates with Gradle and that's the preferred and most advanced way of assembling apks for apps.
Referencing libs
Gradle has what Maven has and more.
<project>
<dependencies>
<dependency>
<groupId>com.github.bumptech.glide</groupId>
<artifactId>glide</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
</project>
is the same as (be careful this is not the same as buildscript { dependencies { ... } })
dependencies {
compile 'com.github.bumptech.glide:glide:3.3.1'
}
See the Dependency Information in the Maven Central search for this lib: http://search.maven.org/#artifactdetails%7Ccom.github.bumptech.glide%7Cglide%7C3.3.1%7Cjar

Categories