科特林Gradle:如何将db配置文件(hikari.conf)包含在分布式文件中?

时间:2019-01-10 16:49:22

标签: gradle kotlin hikaricp

我有gradle kotlin项目。

数据库配置文件位于myapp\hikari.conf

在我的build.gradle中:

group 'com.myproject'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.2.31'
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
    }
}

apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'

sourceCompatibility = 1.8
targetCompatibility = 1.8

compileJava {
    targetCompatibility = 1.8
}

compileKotlin {
    kotlinOptions {
        jvmTarget = '1.8'
    }
}


mainClassName = 'com.myproject.upbit.AppStarterKt'

repositories {
    mavenCentral()
    jcenter()
    maven {
        url "http://mvn.neemre.com"
    }
    maven { url "https://jitpack.io" }
}

AppStarter.kt文件中,我这样读取配置:

val dbConfig = HikariConfig("hikari.conf") 
val ds = HikariDataSource(dbConfig)

在IntelliJ IDEA中,我成功构建并运行了项目。

但是,如果我创建分发版,则会遇到问题:

1. gradlew distZip
2. Extract zip in any folder
3. run bin/myapp.bat

但是我得到了错误:

Exception in thread "main" java.lang.IllegalArgumentException: Cannot find property file: hikari.conf
        at com.zaxxer.hikari.HikariConfig.loadProperties(HikariConfig.java:1085)
        at com.zaxxer.hikari.HikariConfig.<init>(HikariConfig.java:148)
at AppStarterKt.main(AppStarter.kt:40)

此行中的错误:

val dbConfig = HikariConfig("hikari.conf")

那么我如何将hikari.conf包含在分布中?

0 个答案:

没有答案