KotlinアプリケーションをGradleで走らせようとしています。
ローカル環境(Windows10 Gradle3.1)では gradle build
が成功するのに対し、本番サーバ(CentOS6.7 Gradle3.2.1)では失敗します。
なにをどのように修正すれば本番環境でも gradle build
が成功するようになるのでしょうか?
gradle build
の実行結果は以下のようになりました。
gradle build :compileKotlin e: /home/my/batch/kotlin/src/main/kotlin/net/my/kotlin/mail/Mail.kt: (84, 44): No value passed for parameter p1 e: /home/my/batch/kotlin/src/main/kotlin/net/my/kotlin/services/TmpKaiinService.kt: (29, 48): No value passed for parameter p1 :compileKotlin FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileKotlin'. > Compilation error. See log for more details * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 2.518 secs
gradle -d build
の実行結果は teratail の投稿可能文字数を超えてしまうため、 gradle_build.log としてGistに添付しました。
該当箇所のソースはどちらも val path = Paths.get(ClassLoader.getSystemResource("db/database.yaml").toURI())
のようにClassLoaderから src/main/resources
配下のファイルを読み込む処理となっています。
kotlin
1class TmpKaiinService(val target: String) { 2 val tableName: String = "tmp_kaiin" 3 val logger: Logger = LoggerFactory.getLogger(TmpKaiinService::class.java) 4 val database: Database 5 6 init { 7 val path = Paths.get(ClassLoader.getSystemResource("db/database.yaml").toURI()) 8 database = Files.newBufferedReader(path).use { 9 val mapper = ObjectMapper(YAMLFactory()) // Enable YAML parsing 10 mapper.registerModule(KotlinModule()) // Enable Kotlin support 11 mapper.readValue(it, Database::class.java) 12 } 13 }
build.gradle
は以下のように記載しています。
Groovy
1group 'kotlin-test' 2version '1.0-SNAPSHOT' 3 4buildscript { 5 ext.kotlin_version = '1.0.5-2' 6 7 repositories { 8 mavenCentral() 9 } 10 dependencies { 11 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 12 } 13} 14 15apply plugin: 'kotlin' 16apply plugin: 'application' 17mainClassName = 'net.my.kotlin.AppKt' 18 19sourceCompatibility = 1.7 20targetCompatibility = 1.7 21 22sourceSets { 23 main.kotlin.srcDirs += 'src/main/kotlin' 24} 25 26repositories { 27 mavenCentral() 28} 29 30dependencies { 31 compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 32 compile 'ch.qos.logback:logback-classic:1.1.7' 33 34 compile 'me.mattak:moment:0.0.4' 35 36 // DB Access 37 compile 'mysql:mysql-connector-java:6.0.5' 38 compile 'com.gitblit.iciql:iciql:2.1.1' 39 40 // YAML Parser 41 compile 'com.fasterxml.jackson.core:jackson-databind:2.7.1-1' 42 compile 'com.fasterxml.jackson.module:jackson-module-kotlin:2.7.1-2' 43 compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.7.1' 44 45 // Mail 46 compile 'org.jodd:jodd-mail:3.8.0' 47 48}