Reputation: 36031
Any idea how to obtain the source code for Kotlin's stdlib?
In the screencap below, I don't have any option to download the source code like other maven libraries.
I'm using the following Kotlin dependency:
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>1.2.30</version>
</dependency>
Upvotes: 21
Views: 5335
Reputation: 4596
We can solve this by
=> manually importing source code in intelliJ-idea
Get source file from github-release
I selected 1.6.21 and added at following macos path(or find .m2 maven folder at respective OS)
/Users/${USER}/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/<kotlin-version>
e.g.
/Users/${USER}/.m2/repository/org/jetbrains/kotlin/kotlin-stdlib/1.6.21
When IDE prompts to download a source or attach a source, similar to following screen
Verify by checking the implementation of take for String class i.e. "abcd".take(3)
.
when you go to take method's implementation before IDE decompiles String class and points to StringsKt.java
but after source is attached it points to _Strings.kt
And it looks as
OR
=> You can add following code to build.gradle.kts
, in latest kotlin version, source is getting downloaded along with versions so no manual effort.
// Add idea plugin
plugins {
id("idea")
}
// configure idea plugin
idea {
module {
isDownloadJavadoc = true
isDownloadSources = true
}
}
Upvotes: 1
Reputation: 18020
Take in note of not all classes present in ...-source.jar (e.g. missed mutableSetOf()
in Sets.Kt
)
Upvotes: 0
Reputation: 601
For me it helps to change maven dependency on Kotlin in pom.xml from
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>1.2.30</version>
</dependency>
to
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.3.31</version>
</dependency>
</dependencies>
more info on adding Kotlin to project as maven dependency can be found here: https://kotlinlang.org/docs/reference/using-maven.html
Upvotes: 3