Kotlin/Gradle/JUnit starter project

A quick tutorial to bootstrap a Kotlin project using Gradle. Optionally, JUnit can also be added.

Luís Soares
2 min readMay 15, 2022
  1. Download and install IntelliJ Community, free for Java/Kotlin projects. Alternatively, you can use IntelliJ Ultimate EAP (no subscription is required).
  2. Go to “File” ⇀ “New project”;
  3. Pick Kotlin on the left menu;
  4. Write a Name and pick a Location;
  5. Activate “Create Git repository” (to ensure you don’t lose your work and can always go back in time — even if only locally);
  6. Build system: “Gradle”;
  7. JDK: Pick any JDK. If you’re unsure which to pick, go to “Download JDK” (in the dropdown) and select the latest “Oracle OpenJDK”. If you get a warning, decrease one version because Gradle may not support it yet.
  8. Gradle DSL: Pick “Kotlin” as Gradle DSL. Since we’re using Kotlin, it makes sense that the Gradle DSL is Kotlin.
  9. In “Advanced Settings”, pick the latest available Gradle.
  10. Press “Create”.
  11. Optionally, simplify the .gitignore file solely with:
    /.gradle
    /.idea
    /build
  12. Upgrade Kotlin at build.gradle.kts:
    plugins {
    kotlin("jvm") version "LATEST_KOTLIN"
    }
  13. JUnit gets automatically set up for you. Create a dummy test at src/test/kotlin/SmokeTest.kt (import from kotlin.test namespace):
    class SmokeTest {
    @Test fun `seems ok`() = assertTrue(true)
    }
    Notice that we’re using the imports from Kotlin Test, which abstract JUnit but are the same.
  14. Now, run the test (there’s a ️▶️ near the test) to prove that the JUnit setup is good (you can also run the tests with ./gradlew test):

📝 After updating libraries, you may need to click on the second icon to force a Gradle refresh:

📝 We’ve used IntelliJ IDEA to create a new Kotlin project. However, there’s an alternative way that relies on Gradle.

--

--

Luís Soares

I write about automated testing, Lean, TDD, CI/CD, trunk-based dev., user-centric dev, domain-centric arch, ...