やりたいこと
JavaのプロジェクトにKotlinを入れたい
発生した状況
build.gradleの差分
diff --git a/build.gradle b/build.gradle
index xxxxxxxxxx..xxxxxxxx
--- a/build.gradle
+++ b/build.gradle
@@ -6,6 +6,7 @@ plugins {
id '...'
id '...'
id '...'
+ id 'org.jetbrains.kotlin.jvm' version '1.4.10'
}
+
+compileKotlin {
+ kotlinOptions.jvmTarget = '1.8'
+}
エラー (正確にはSuccessを返しているが、buildで失敗する)
> Task :prepareKotlinBuildScriptModel UP-TO-DATE
<ij_msg_gr>JEE project import errors<ij_msg_gr><ij_nav>/path/to/project/build.gradle<ij_nav><i><b>root project 'example': Web Facets/Artifacts will not be configured properly</b><eol>Details: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':runtimeClasspath'.<eol>Caused by: org.gradle.internal.locking.LockOutOfDateException: Resolved 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10' which is not part of the dependency lock state</i>
Could not resolve: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10
Could not resolve: org.jetbrains.kotlin:kotlin-stdlib:1.4.10
Could not resolve: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10
Could not resolve: org.jetbrains.kotlin:kotlin-stdlib-common:1.4.10
Could not resolve: org.jetbrains:annotations:13.0
KotlinDslScriptsParameter(correlationId=176802187286571, scriptFiles=[]) => StandardKotlinDslScriptsModel(scripts=[], commonModel=CommonKotlinDslScriptModel(classPath=[], sourcePath=[], implicitImports=[]), dehydratedScriptModels={}) - took 0.0 secs
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 1s
エラーの意味がよくわからずドハマリ…(Facets??, Artifacts??)
解決策
gradle 7.0を勧められるのに違和感を覚え、gradleのバージョンとkotlinのバージョンに繋がりがあるのかと推測
./gradlew --versionに記載されるkotlinのバージョンに変更したら動作した
(下の例だと1.3.70)
❯ ./gradlew --version
Welcome to Gradle 6.3!
Here are the highlights of this release:
- Java 14 support
- Improved error messages for unexpected failures
For more details see https://docs.gradle.org/6.3/release-notes.html
------------------------------------------------------------
Gradle 6.3
------------------------------------------------------------
Build time: 2020-03-24 19:52:07 UTC
Revision: bacd40b727b0130eeac8855ae3f9fd9a0b207c60
Kotlin: 1.3.70
Groovy: 2.5.10
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 1.8.0_232 (Amazon.com Inc. 25.232-b09)
OS: Mac OS X 10.14.6 x86_64
謎
でもkotlinで作ったプロジェクトはもっと上のバージョンを指定しても動作する