Ray Rahke
04/18/2024, 6:40 AMgradle initVampire
04/18/2024, 6:51 AMkotlin.sourceSets.main.kotlin.srcDir("src")Ray Rahke
04/18/2024, 6:56 AMRay Rahke
04/18/2024, 6:56 AMRay Rahke
04/18/2024, 6:56 AMRay Rahke
04/18/2024, 6:57 AMRay Rahke
04/18/2024, 6:57 AMRay Rahke
04/18/2024, 6:58 AMhfhbd
04/18/2024, 7:11 AMRay Rahke
04/18/2024, 7:14 AMRay Rahke
04/18/2024, 7:15 AMapplication {
    // Define the main class for the application.
    mainClass = "org.example.AppKt"
}hfhbd
04/18/2024, 7:22 AMapphfhbd
04/18/2024, 7:23 AMhfhbd
04/18/2024, 7:26 AMhfhbd
04/18/2024, 7:28 AMMainKtRay Rahke
04/18/2024, 7:33 AMBTW regarding main class: If you want to write a top level main function in Kotlin, you need to specify the Kotlin file name in PascalCase and add a Kt suffix: likestuff like this is why gradle is so hard. Where and when would I have ever learned that?, because the Kotlin compiler creates an JVM class under the hood.MainKt
Ray Rahke
04/18/2024, 7:33 AMhfhbd
04/18/2024, 7:35 AMstuff like this is why gradle is so hard.That's unrelated to Gradle but to Kotlin. Yes, JetBrains could create another Gradle plugin:
kotlin-applicationRay Rahke
04/18/2024, 7:37 AMRay Rahke
04/18/2024, 7:37 AMRay Rahke
04/18/2024, 7:38 AMhfhbd
04/18/2024, 7:43 AMVampire
04/18/2024, 7:46 AMappinitbasicio.github.youusername....initappapporg/example/App.ktAppKtRay Rahke
04/18/2024, 7:46 AMBut you do want to target the JVM and use the Java stdlib? Without knowledge of the JVM/Java?no, not really. I picked Kotlin because it had a language feature set and syntax that I found very attractive. I have little interest in JVM compatibility and android development.
Ray Rahke
04/18/2024, 7:47 AMVampire
04/18/2024, 7:47 AMVampire
04/18/2024, 7:48 AMRay Rahke
04/18/2024, 7:55 AM/*
 * This file was generated by the Gradle 'init' task.
 *
 * This is a general purpose Gradle build.
 * To learn more about Gradle by exploring our Samples at <https://docs.gradle.org/8.6/samples>
 * This project uses @Incubating APIs which are subject to change.
 */Ray Rahke
04/18/2024, 7:55 AMRay Rahke
04/18/2024, 7:56 AMsourceSets {
    main {
        kotlin.srcDir("src/")
    }
}Adam S
04/18/2024, 7:57 AMVampire
04/18/2024, 7:58 AMRay Rahke
04/18/2024, 7:59 AMAdam S
04/18/2024, 8:01 AMVampire
04/18/2024, 8:01 AMbasicRay Rahke
04/18/2024, 8:03 AMRay Rahke
04/18/2024, 8:03 AMRay Rahke
04/18/2024, 8:03 AMRay Rahke
04/18/2024, 8:03 AMRay Rahke
04/18/2024, 8:04 AMAdam S
04/18/2024, 8:04 AMsourceSets {
    main {
        kotlin.setSrcDirs(listOf("src"))
        resources.setSrcDirs(listOf("resources"))
        java.setSrcDirs(emptyList<String>())
    }
    test {
        kotlin.setSrcDirs(listOf("testSrc"))
        resources.setSrcDirs(listOf("testResources"))
        java.setSrcDirs(emptyList<String>())
    }
}setSrcDirsRay Rahke
04/18/2024, 8:05 AMBuild file '/Users/ray/test/build.gradle.kts' line: 1
* What went wrong:
Script compilation errors:
  Line 1: sourceSets {
          ^ Unresolved reference: sourceSetsRay Rahke
04/18/2024, 8:05 AMAdam S
04/18/2024, 8:06 AMplugins {}Ray Rahke
04/18/2024, 8:06 AMplugins {
    kotlin("jvm") version "1.9.23"
}
sourceSets.main {
    java.srcDirs("src/main/myJava", "src/main/myKotlin")
}hfhbd
04/18/2024, 8:08 AMRay Rahke
04/18/2024, 8:09 AMRay Rahke
04/18/2024, 8:09 AMAdam S
04/18/2024, 8:10 AMAdam S
04/18/2024, 8:10 AMRay Rahke
04/18/2024, 8:10 AM------------------------------------------------------------
Gradle 8.6
------------------------------------------------------------
Build time:   2024-02-02 16:47:16 UTC
Revision:     d55c486870a0dc6f6278f53d21381396d0741c6e
Kotlin:       1.9.20
Groovy:       3.0.17
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          21.0.2 (Homebrew 21.0.2)
OS:           Mac OS X 14.2.1 aarch64Adam S
04/18/2024, 8:12 AMRay Rahke
04/18/2024, 8:13 AMplugins {
    kotlin("jvm") version "1.9.23"
}
sourceSets.main {
    java.srcDirs("src/main/myJava", "src/main/myKotlin")
}Ray Rahke
04/18/2024, 8:14 AMplugins {
    kotlin("jvm") version "1.9.23"
}
sourceSets {
    main {
        java.srcDirs("src/main/myJava", "src/main/myKotlin")
    }
}* What went wrong:
Task 'run' not found in root project 'test'.
* Try:
> Run gradlew tasks to get a list of available tasks.Adam S
04/18/2024, 8:14 AMRay Rahke
04/18/2024, 8:15 AMAdam S
04/18/2024, 8:15 AMRay Rahke
04/18/2024, 8:15 AMAdam S
04/18/2024, 8:16 AMgradle runRay Rahke
04/18/2024, 8:17 AMhfhbd
04/18/2024, 8:17 AMRay Rahke
04/18/2024, 8:17 AMAdam S
04/18/2024, 8:17 AMplugins {
    kotlin("jvm") version "1.9.23"
    application
}
sourceSets.main {
    java.srcDirs("src/main/myJava", "src/main/myKotlin")
}
application {
    mainClass.set("my.package.MainKt") // The main class of the application
}src/main/myKotlin/main.ktpackage my.packagefun main() {}Ray Rahke
04/18/2024, 8:17 AMAdam S
04/18/2024, 8:18 AM.kt.class.jarRay Rahke
04/18/2024, 8:18 AMjava.srcDirs("src/main/myJava", "src/main/myKotlin")Ray Rahke
04/18/2024, 8:18 AMAdam S
04/18/2024, 8:19 AMjava.srcDirs()Adam S
04/18/2024, 8:21 AMKotlin sources and Java sources can be stored in the same directory, or they can be placed in different directories.So I think the point of the example is to demonstrate how the directory names don't have to be strict. It's not an example of best practice. But the example doesn't make that clear, so I'm not sure...
Ray Rahke
04/18/2024, 8:24 AMRay Rahke
04/18/2024, 8:24 AMAdam S
04/18/2024, 8:30 AMRay Rahke
04/18/2024, 8:30 AMRay Rahke
04/18/2024, 8:30 AMRay Rahke
04/18/2024, 8:31 AMAdam S
04/18/2024, 8:31 AMRay Rahke
04/18/2024, 8:31 AMRay Rahke
04/18/2024, 8:31 AMRay Rahke
04/18/2024, 8:32 AMRay Rahke
04/18/2024, 8:32 AMRay Rahke
04/18/2024, 8:32 AMRay Rahke
04/18/2024, 8:33 AM* What went wrong:
Execution failed for task ':run'.
> Could not resolve all files for configuration ':runtimeClasspath'.
   > Cannot resolve external dependency org.jetbrains.kotlin:kotlin-stdlib:1.9.23 because no repositories are defined.
     Required by:
         project :Ray Rahke
04/18/2024, 8:34 AMRay Rahke
04/18/2024, 8:34 AMRay Rahke
04/18/2024, 8:35 AMRay Rahke
04/18/2024, 8:35 AMRay Rahke
04/18/2024, 8:38 AMVampire
04/18/2024, 8:41 AMalso I still dont understandjava.srcDirs("src/main/myJava", "src/main/myKotlin")
why is this in java.srcDirsI guess this is meant for when you mix Java and Kotlin and want to also have them side-by-side, so putting your Java classes into
src/main/myKotlin