IntelliJ shows a *.class file, not a *.kt for the library i published to Maven Central

57 Views Asked by At

I published a library written in kotlin to Maven Central. (using sona type)

I tried to use it other project. I can use but IntelliJ IDEA just show *.class file when i go to the implementation(Ctrl+B) for the library.

I checked that \*-sources.jar is published and it pulled in my local storage successfully.
(C:/Users/[username]/.gradle/caches/modules-2/files-2.1/io.github.jinlee0/rusult/0.1.1/bd76f82bcfedf76e2146af416ed06a1991f55ace/rusult-0.1.1-sources.jar)

For other libraries (kotlin-stdlib-common, spring etc...), IntelliJ shows *.java or *.kt files in *-sources.jar well.

Here is my github repo of the library and it contains publication scripts.

Something wrong in publication? Or the setting of IDE is wrong?

Please help me.


build.gradle.kts

publish.gradle

scripts/publish-maven.gradle

I am expecting that the IDE shows *.kt file, not the *.class file for the library i published.

1

There are 1 best solutions below

0
Joffrey On

Your published sources jar doesn't contain anything on maven central (apart from a manifest): neither compiled classes nor sources.

Looking at your code here:

task sourcesJar(type: Jar) {
    archiveClassifier.set("sources")
}

You create a custom task named sourcesJar, but it has almost zero configuration. Namely it doesn't put anything in that jar. So the published empty jar makes sense.

There is little the IDE can do about this after that point.

I suggest you fix your javadoc and sources tasks. Since you're using the Kotlin/JVM gradle plugin, you should be able to use:

java {
    withSourcesJar()
}

which removes the need for custom tasks.

If you want to simplify your whole script, I wrote a plugin to streamline the publication logic. Maybe it can help: https://github.com/joffrey-bion/gradle-kotlin-publish-plugin