Kotlin/Gradle/JUnit starter project
A quick tutorial to bootstrap a Kotlin project using Gradle. Optionally, JUnit can also be added.
2 min readMay 15, 2022
- Download and install IntelliJ Community, free for Java/Kotlin projects. Alternatively, you can use IntelliJ Ultimate EAP (no subscription is required).
- Go to “File” ⇀ “New project”;
- Pick Kotlin on the left menu;
- Write a Name and pick a Location;
- Activate “Create Git repository” (to ensure you don’t lose your work and can always go back in time — even if only locally);
- Build system: “Gradle”;
- 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.
- Gradle DSL: Pick “Kotlin” as Gradle DSL. Since we’re using Kotlin, it makes sense that the Gradle DSL is Kotlin.
- In “Advanced Settings”, pick the latest available Gradle.
- Press “Create”.
- Optionally, simplify the .gitignore file solely with:
/.gradle
/.idea
/build - Upgrade Kotlin at build.gradle.kts:
plugins {
kotlin("jvm") version "LATEST_KOTLIN"
} - JUnit gets automatically set up for you. Create a dummy test at src/test/kotlin/SmokeTest.kt (import from kotlin.test namespace):
class SmokeTest {
Notice that we’re using the imports from Kotlin Test, which abstract JUnit but are the same.
@Test fun `seems ok`() = assertTrue(true)
} - 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.