How to attach the Kotlin library sources?


#1

I seem to have lost the source attachment with the latest update (I can no longer go to a source inside the Kotlin libraries). When I click on the "Attach sources" hyperlink and I get presented with a dialog, which path should I put there? It's not quite clear to me from the folder structure of the github project...

Thanks.


#2

It's easy: you need to put the path to root folder which contains sources. If this folder is under jar, there's no problem: you can expand jars as usual folders in this dialog.

If you lost sources of Kotlin runtime, try removing kotlin-runtime.jar and reinstalling it using editor warning bar. If this doesn’t help, maybe there is a bug in navigation to sources.   


#3

Android Studio 1.4 beta 2 (also 1.3, and probably any other) Kotlin plugin 1235, kotlin version 1230

If i do as suggested, i get infinite Attaching… in toolbar
/uploads/kotlinlang/original/1X/23f9058bd87bc204eb82c22f0a6955ecbe4ea5d9.png

Also my library jar have jar with sources, and it’s not resolved either.

/uploads/kotlinlang/original/1X/8490830febe6fa951decb6487d9289e47affcc45.png

I can’t debug code in dependent libraries, its frustrating


#4

Hi Dmitriy,

There is an issue in your tracker (https://youtrack.jetbrains.com/issue/KT-8592). We are investigating where the problem is.


#5

Issue is only about Choose Sources dialog(basically an IDE problem?) But i also can't get sources in normal case, with dependency via gradle.


#6

Could you attach your build.gradle file to the issue, please? How did you configure sources for your library? Is the library written in Kotlin?


#7

Natalia, i found my problem:

build.gradle in kotlin library project has setting:

task sourceJar(type: Jar) {
    from sourceSets.main.allJava
}

i got an empty sources jar

is it possible that on older versions of kotlin it works correctly? because i tested it before and it worked Oo
I assume that after m12 manipulations with possibility to place java and kotlin files in same folder it was broken.

now i changed it to:

task sourcetypepepe: Jar) {
    from sourceSets.main.allSources
}

and it works now.


#8

However i can't fix android-library source attaching (aar)

for example i can’t see sources for http://search.maven.org/#artifactdetails%7Cio.reactivex%7Crxandroid%7C1.0.1%7Caar
and also for my own android libraries.

task androidSourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.sourceFiles
}

sources are generated and i can see them under .jar, but can't get it to work in AS


#9

I fail to generate sources using your last hint above.
The sources.jar gets genrated, but it contains only empty directories and no kt files.

Is there some documentation somewhere on how one would go about creating a kotlin (android) library along with a sources .jar?

I also use my kotlin library in a java based project and I wonder - what should I do to document it, for the users to see