###背景
Kotlinの勉強を始めたので、Hello World プログラムを Gradle プロジェクトとして作ろうとしている
###ソースコード
公式サイト を見ながら、下記の build.gradle ファイルを(わりと適当な感じで)作成しました。
buildscript { ext { kotlin_version = "1.1.2-2" } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } plugins { id "org.jetbrains.kotlin.jvm" version "$kotlin_version" } repositories { mavenCentral() } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-jre8" }
###発生するエラー
FAILURE: Build failed with an exception. * Where: Build file 'XXXX/build.gradle' line: 12 * What went wrong: Could not compile build file 'XXXX/build.gradle'. > startup failed: build file 'XXXX/build.gradle': 12: argument list must be exactly 1 literal non empty string See https://docs.gradle.org/3.5/userguide/plugins.html#sec:plugins_block for information on the plugins {} block @ line 12, column 5. id "org.jetbrains.kotlin.jvm" version "$kotlin_version" ^ 1 error * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
###エラーの考察
どうやら、"$kotlin_version" が解決できずに、空文字になってしまっているようです。ためしに
plugins { id "org.jetbrains.kotlin.jvm" version "1.1.2-2" }
と直接バージョンを記載すれば正常にビルドできます。
もちろん、plugins DSL を使わずに
apply plugin: 'kotlin'
としても(buildscript にmavenCentralを追加すれば)動作します。
###質問事項
いかんせんコピペでしか build.gradle を書いたことがないので、書き方を間違えている気がしますが、plugins DSL を利用する時に、プラグインのバージョン指定をいい感じに変数にする方法が知りたいです。
kotlin-gradle-plugin と kotlin プラグインの指定で 2回 "1.1.2-2" のリテラルが登場するとモヤモヤしてしまう。
###バージョン情報
$ gradle -version ------------------------------------------------------------ Gradle 3.5 ------------------------------------------------------------ Build time: 2017-04-10 13:37:25 UTC Revision: b762622a185d59ce0cfc9cbc6ab5dd22469e18a6 Groovy: 2.4.10 Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015 JVM: 1.8.0_131 (Oracle Corporation 25.131-b11) OS: Linux 4.4.0-53-generic amd64
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。