Junior
Gradle veya Maven kullanarak Kotlin projesi nasıl yapılandırılır?
sobes.tech yapay zeka
AI'dan gelen yanıt
IDE (tercihen IntelliJ IDEA için Kotlin) kullanarak yeni bir proje oluşturun ve gerekli framework ile Kotlin şablonunu seçin (örneğin, Spring Boot veya Ktor).
Gradle:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.9.22' // Güncel Kotlin sürümünü belirtin
id 'application' // İsteğe bağlı, çalıştırılabilir JAR'lar için
}
group = 'com.example'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
// Test için örnek bağımlılık
testImplementation kotlin('test')
}
tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(17) // Gerekirse JVM sürümünü belirtin
}
build.gradle.kts(veyabuild.gradle) dosyasınaorg.jetbrains.kotlin.jvmeklentisi eklenir.- Kotlin eklentisinin sürümü belirtilir.
kotlin-stdlibbağımlılığı eklenir.
Maven:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-kotlin-project</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.9.22</kotlin.version> <!-- Güncel Kotlin sürümünü belirtin -->
<maven.compiler.source>17</maven.compiler.source> <!-- JVM sürümünü belirtin -->
<maven.compiler.target>17</maven.compiler.target> <!-- JVM sürümünü belirtin -->
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<!-- Test için örnek bağımlılık -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <!-- Güncel sürüm belirtin -->
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
kotlin-stdlibbağımlılığıpom.xmldosyasına eklenir.- Kotlin kodunu derlemek için
kotlin-maven-plugineklentisi eklenir. - Kotlin kaynak kodu dizinleri yapılandırılır.
Daha sonra, proje seçilen bağımlılık yöneticisi ile senkronize edilmelidir.