Kotlin 101: Library package maven vs gradle quickstart guide for non java track devs jumping into kotlin

I’ve been using kotlin for the past 2 weeks or so.
I would appreciate if someone could tell me How to get started in IntelliJ using an NPM equivalent. I was able to right-click on my project module settings and select from a Maven repository an org.something library to download just to try it out.

I understand there is some xmlish pom.xml in Java projects

I understand that there is something called build.gradle.kts and I dont see it in IntelliJ project directory.

So as I setup up the typical Kotlin project there I see:
/lib
/out
/src

amongst External dependencies but its not clear where do I find a package file as such.

I see it in the project module settings as I previously mentioned. but no build.gradle.kts (or is there supposed to be one?)

Also, When to use Maven/Gradle? And in the typical InteliJ kotlin project setup I assume it is gradle. So when/how do I switch to Maven ?
And I see both com.something.gradle and maven libraries over there. So what is the difference?

Also, I understand there is some xmlish pom.xml in Java projects. If the gradle equivalent

IntelliJ has it’s own build system if you do not select a differnt one when you create your project. When you click “New Project”, you want to select “Gradle” on the right and then “Kotlin”. That way IntelliJ creates a “build.gradle” file (or “build.gradle.kts” if you check the “Kotlin DSL Build Script”).

You don’t want to. In general gradle is the prefered build system for kotlin. Maven support is mainly for big companies that don’t want to switch. Also features like mpp or native aren’t available for maven.

Not sure what you mean. Where do you see that?

pom.xml is the maven equivalent of build.gradle.

You should take a look at: https://kotlinlang.org/docs/reference/using-gradle.html

thanks. so if you right click over project > open module settings and see modules. you can add lets say com.pinterest:ktlint from maven, IF you install it in the Libraries.

so does that mean i can add both gradle and maven files?

Basically you mention inteliJ handles with its own build system, so if i wana add libraries to the project, i can add from both maven and gradle?

If I understand you corectly yes. The problem I have with this question is that it technically doesn’t make sense. If you add a dependency on a library you create a dependency on a jar file and a jar file has nothing to do with any build system, not gradle nor maven. You can however create a jar with maven or gradle.

Hi @codecakes I can help you with a website/repo where you can find 5 different version of build dependency code for the same binary

http://mvnrepository.com/

you can search the mvn binary you want and switch the tab to get gradle, SBT, Ivy, Grape, Leiningen, Buildr version of dependency code for the same binary

if you have eclipse, you can generate build.gradle for pom.xml or vice versa is few minutes

you can definitely keep both, gradle and maven based, technically a nexus can serve any build system for binary download

ok so gradle/maven being like npm, can get the lib for me. thats what i wanted to know. plus it clears somethings up.

thanks for the info. well basically i m understanding the package manager support in kotlin and understanding how different package managers work for diff jvm based langs. dont know for which lang ivy and Grape build systems are for.

If i have made a project and now want to export it to github with package requirements from inteliJ how do I do that? Also generating a jar also generates its package requirement list like pom.xml or in gradle format?

Publishing to a repository should be your question or creating a repo with github

GitHub has a documentation
GitHub Packages
About GitHub Packages

I also recomend Bintray which is used by kotlin
Bintray
in the bottom there is a free account for open source

If you are going to put code on github, best practice is to have a working build script that does not rely on any particular IDE. All of the libraries you depend on should be declared in your build script, rather than being added directly via the IntelliJ UI. If you do it this way, IntelliJ will detect the added libs when you re-import the project, however libs added via the IntelliJ project dependencies screen will not be added to your build script. If you mix the two approaches, your build script will not be able to build your project, due to missing dependencies - although it may well build in IntelliJ, because IntelliJ also imports dependencies from your build script.

As recommended previously in this thread, gradle should be your preferred option for kotlin. See the gradle docs for the detail of how to add dependencies using gradle: Managing Dependencies of JVM Projects

Regarding package managers for kotlin, there is not really any direct equivalent for npm, in that there is no canonical command line tool for fetching/installing/updating libraries. Instead, JVM projects rely on their build tools to manage dependencies.

As a build script author, you typically do not have to worry about the distinction between Ivy and Maven. Your build tool of choice will expose a way of managing dependencies that will be fully compatible with Maven repositories.

Ivy is basically a superset of Maven’s dependency management features, but provides additional flexibility, configurability and better conflict resolution. It fully supports Maven repositories, but some Ivy features require additional metadata that is not available in Maven repositories. Again, this functionality is typical exposed as features of your build tool; you don’t need to separately install/use Ivy.

See the gradle docs if you want to better understand the distinction:
https://docs.gradle.org/current/userguide/declaring_repositories.html