Given a typical Kotlin project, where should you place your main application code?
Main application code goes in the source folder for production code, not tests or build outputs.
The src/main/kotlin folder is the standard place for Kotlin source files that make up the main application. Test code goes under src/test/kotlin. The build folder contains compiled outputs, and lib is not a standard source folder.
What will be the output of running gradle tasks in a Kotlin project with a standard Gradle build?
Think about what the tasks command does in Gradle.
The gradle tasks command lists all the tasks available in the project. It does not perform compilation, execution, or cleaning by itself.
Consider this snippet from a build.gradle.kts file:
plugins {
kotlin("jvm") version "1.5.0"
}
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
testImplementation("junit:junit:4.13.2")
}
application {
mainClass.set("com.example.MainKt")
}What error will Gradle report when trying to build?
Check if the application block is recognized by Gradle without applying the right plugin.
The application block requires the application plugin to be applied. Since it is missing, Gradle will report an unresolved reference error for application.
Given this Kotlin main function in src/main/kotlin/com/example/Main.kt:
package com.example
fun main() {
println("Hello from Kotlin Gradle project!")
}What is the output when you run gradle run after configuring the application plugin correctly?
Running gradle run executes the main function if configured properly.
With the application plugin and mainClass set, gradle run executes the main function and prints the message.
Which Gradle build phase is responsible for compiling Kotlin source code?
Think about when tasks actually run during a Gradle build.
Gradle has three main phases: initialization, configuration, and task execution. The compilation happens during the task execution phase when the compileKotlin task runs.