Skip to content

Maven Setup

Daniel Ennis edited this page Mar 14, 2018 · 2 revisions

Maven

First you will need to add the repositories and the dependency to your pom.xml You will also need to shade the library into your application / plugin jar.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>


    <repositories>
        <repository>
            <id>aikar</id>
            <url>https://repo.aikar.co/content/groups/aikar/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>co.aikar</groupId>
            <artifactId>idb-core</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>2.4.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
                    <relocations>
                        <relocation>
                            <pattern>co.aikar.idb</pattern>
                            <shadedPattern>[PACKAGE].idb</shadedPattern>
                        </relocation>
                    </relocations>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Replace [PACKAGE] with a package to your plugin so that IDB is relocated to it.

JDBC Driver

You also need to make sure your respective JDBC driver (MySQL, etc) is shaded/available

For the utility .mysql() method on the options builder, the standard MySQL driver is expected: mysql:mysql-connector-java:5.1.33 which uses the class com.mysql.jdbc.jdbc2.optional.MysqlDataSource

Bukkit Minecraft Servers: This is already included for you, you do not need to add it.

Bukkit Minecraft Servers

If using Bukkit, A bukkit specific setup class is provided where you can pass your plugin and mysql information and get some defaults pre setup. This will set up some of the configuration for you such as DB Pool name, Logger and automatic closing on plugin disable. Example:

Database db = BukkitDB.createHikariDatabase(this, dbUser, dbPass, dbName, hostAndPort);
// Global is already set for you.

Setup:

    <dependencies>
        <dependency>
            <groupId>co.aikar</groupId>
            <artifactId>idb-bukkit</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

Then use BukkitDB class to initialize with your plugin to automatically close the database on disable.

idb-bukkit is optional, as you can do this stuff yourself with just core

Clone this wiki locally