> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codecrafters.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Kotlin

> Learn how to solve CodeCrafters challenges in Kotlin

> [!NOTE]
>
> **New to Kotlin?** We recommend checking out [Kotlin
> Koans](https://play.kotlinlang.org/koans/overview) to get up to speed.

## Local development

To run the code for your challenge locally, you'll need `mvn` installed. Our test runners use `mvn` version `3.9.5` (as of November 2023).

The script for your challenge (like `./your_bittorrent.sh`) will automatically compile your code using `mvn package` before executing it.

## File structure

* The files for your solution are placed in the `src/main/kotlin` directory.
* `src/main/kotlin/Main.kt` contains the `main` function, which is what the test runner executes.

## Adding more files

You can add more files and directories to `src/main/kotlin`. The test runner will include them when compiling your code.

For example, if you added a file at `src/main/kotlin/Foo.kt`, you could use it like so:

```kotlin src/main/kotlin/Main.kt theme={null}
fun main() {
    foo() // Uses the foo function from Foo.kt
}
```

```kotlin src/main/kotlin/Foo.kt theme={null}
fun foo() {
    println("Hello world!")
}
```

By default, all files in `src/main/kotlin` are in the `default` package. If you want to extract files into a different package,
you'll need to add a `package` declaration to the top of the file.

Let's say you wanted to extract `Foo.kt` into the `com.example.foo` package. You'd add the following to the top of `Foo.kt`:

```kotlin src/main/kotlin/Foo.kt theme={null}
package com.example

fun foo() {
    println("Hello world!")
}
```

```kotlin src/main/kotlin/Main.kt theme={null}
fun main() {
    com.example.foo() // Uses the foo function from Foo.kt
}
```

## Adding dependencies

You can add dependencies to your project by adding them to your `pom.xml` file.

For example, to add the gson library, add the following to the `<dependencies>` section in your `pom.xml`:

```xml theme={null}
<dependency>
  <groupId>com.google.code.gson</groupId>
  <artifactId>gson</artifactId>
  <version>2.8.6</version>
</dependency>
```

When you push your code next, the runner will automatically download the dependency.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.