Add gradle to existing Kotlin IDEA project

In fact, I have more than one question described in title but they all are linked together.

  1. Do I have to use gradle with my incredibly simple project (e.g. test project which I want to use for playing with Kotlin, some libraries and frameworks, checking how smth works etc.) if I need to have there a package management but don’t need any build system (idea can build simple projects itself, right?) ?

  2. Do I have to learn Groovy to write build scripts for such projects as described above (or maybe a bit more complicated projects) ? I’m actually confused about necessity of build scripts. I have some experience with Rust and Cargo, for example: cargo can build most projects without any build scripts but it supports them for special needs, so it’s not necessary for a newbie to even know anything about build scripts until he first time faces the need to use them. Java build systems like Gradle or Maven are much more hard to understand for a newbie, because he needs to specially learn them before he can use them for even simplest tasks. Correct me pls if I’m wrong here.

  3. I’ve created a simple Kotlin/JVM project (without Gradle) in IDEA and already wrote some code. Then I understood that I need Gradle there to manage some packages (I’m too lazy to search JARs around the web, download them, collect in special folder, declare CLASSPATHs etc.). How should I add a minimal graddle support into that project and make IDEA understand it and use it?

Very huge thanks in advance for detailed response. :slight_smile:

  1. No, you don’t. Idea’s JPS works just fine for small projects. I would still recommend gradle for something more complicated. And you have to use gradle for Android (it is definitely complicated).

  2. No, you don’t. Basic build scripts looks like some kind of declarative DSL. You do not need to know that it is groovy, just copy the examples. Also kotlin gradle DSL is now released and you can write build scripts in kotlin.

  3. Downloading libraries by hand is a bad idea. You can use maven dependencies in JPS and you can just add build.gradle or build.gradle.kts to your project root and reload the project. IDEA will ask you to import gradle project.

Not sure if I understand what exactly JPS is. Is it some kind of IDEA built-in feature which can manage package dependencies? If yes, how do I use it?
If you are talking about adding “From Maven…” dependency in Project StructureModulesDependencies dialog, I can’t understand how to make it work. When I’m trying to do like that I always get an error message “No files were downloaded for …”. I’ve thought it’s because I try to do it in project without maven. Hm?

JPS is internal Idea build system. You should read the documentation. I don’t use it much, so I can’t help you with that. Also check basic info on maven since it is definitely required to do anything with Java or Kotlin (you do not need to study maven itself just short information about repositories).

I think this page covers everything about dependencies: Libraries | IntelliJ IDEA

LMAO. This problem was solved by adding into Maven Jar Repositories group in Settings → Build, Execution, Deployment → Remote Jar Repositories dialog instead of Artfactory, Nexus or Bintray Service URLs where it was placed by default.
How does it work?

Basically, as I already said you should read about maven. Contrary to, say, Cargo, maven ecosystem does not have default repository. There are two major repositories that could be used more or less interchangeably: maven central and jcenter, which you used. Also there is infinite number of personal and even private repositories. So in order for something to work, you mus declare which repository to use.

OH MY GOD. It seems your are/were going through the same hell as me. I was wading through outdated, misleading and contradictory documentation. Then learn this, learn that. Funny, this guy telling you JPS. This makes my cry.

Then I wanted to try out coroutines. Compile errors everywhere. Why? It’s a library, not a language construct. The only way is to add a dependency. Welcome to build systems fuck up.

The solution I found is: in Project Structure > Modules > Dependencies click on “+” in the list, choose “Libraries”, “From Maven”, enter your search term and then it downloads this, adds it to your project and everything is fine.

The next challenge is to find exactly the right dependency. E.g. for coroutines it’s org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1.