LoginSignup
0
0

More than 5 years have passed since last update.

Kotlinでlettuceを使ってみた(その1:環境設定)

Posted at

Introduction

Kotlinの勉強がてら、Lettuceでredisにアクセスしてみました。その1。

前回までのKotlinシリーズはこちら。

バージョン

本記事作成に用いたOS、言語、ミドルウェア等のバージョンは以下の通りです。

種類 名前 バージョン
OS Ubuntu 18.04(Bionic Beaver)
開発環境 Intellij IDEA ULTIMATE 2018.2
開発言語 Kotlin 1.2.60
JVM OpenJDK 10.0.1
ビルド Gradle 4.9
テスト環境1 JUnit 5.2
テスト環境2 Spek 1.2.0
依存ライブラリ Protobuf 3.6.1
依存ライブラリ Reactor 3.2.0.M4
依存ライブラリ Lettuce 5.0.5
キャッシュサーバ Redis 4.0.11

環境設定

Redis

テスト用にRedisのインストールです。Redisは新しい目のものを使いたいので、PPAからインストールすることにします。

$ sudo add-apt-repository ppa:chris-lea/redis-server
$ sudo apt-get update
$ sudo apt-get install redis-server

protobuf

RedisとProtoBuffersを両方使用することを想定して、protobuf用コンパイラをインストールします。
Ubuntu環境なので、snapを使ってインストールできます。

$ sudo snap install --classic protobuf
$ protoc --version
libprotoc 3.6.1

Gradle各種設定

ビルドに使用したGradle用の設定です。

gradle.properties

環境構築の記事の際に作成したものと同じです。 

gradle.properties
org.gradle.jvmargs=-Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts -Djavax.net.ssl.trustStorePassword=changeit -Dorg.gradle.daemon=false

settings.gradle

gradleのprotobufプラグイン用にgradlePluginPortal()を追加しています。

settings.gradle
pluginManagement {
    repositories {
        mavenCentral()
        gradlePluginPortal()

        // Kotlin
        maven {
            url { 'https://dl.bintray.com/kotlin/kotlin-dev' }
        }
    }
}

rootProject.name = 'lettucework'

build.gradle

Lettuce、Protobufを使用するためのgradleです。
Lettuceで、Nativeのトランスポート層(epoll)を使用できるように設定しています。

plugins {
    // Kotlin
    id 'org.jetbrains.kotlin.jvm' version '1.2.60'

    // Protobuf
    id 'com.google.protobuf' version '0.8.6'
}

sourceSets {
    main.proto.srcDirs += 'src/main/proto'
}

group 'hogehoge'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()

    // Spek
    maven {
        url { 'https://dl.bintray.com/spekframework/spek' }
    }

    // Protobuf
    maven {
        url { 'https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java' }
    }

    // Reactor
    maven {
        url { 'https://repo.spring.io/milestone' }
    }
}

dependencies {
    // Kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

    // JUnit5
    testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5:1.2.60'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.2.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0'

    // Spek
    testImplementation 'org.jetbrains.spek:spek-api:1.2.0'
    implementation 'org.jetbrains.kotlin:kotlin-reflect:1.2.60'
    testRuntimeOnly 'org.jetbrains.spek:spek-junit-platform-engine:1.2.0'

    // Protobuf
    implementation 'com.google.protobuf:protobuf-java:3.6.1'

    // Reactor
    implementation 'io.spring.gradle:dependency-management-plugin:1.0.6.RELEASE'
    implementation 'io.projectreactor:reactor-core:3.2.0.M4'
    testImplementation 'io.projectreactor:reactor-test:3.2.0.M4'

    // Lettuce
    implementation 'io.lettuce:lettuce-core:5.0.5.RELEASE'
    implementation 'io.netty:netty-transport-native-epoll:4.1.28.Final:linux-x86_64'
    implementation 'io.netty:netty-transport-native-unix-common:4.1.28.Final:linux-x86_64'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

test {
    useJUnitPlatform()
}

protobuf {
    generatedFilesBaseDir = "$projectDir/src"
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0