im following a book and it says to start a new pro...
# getting-started
e
im following a book and it says to start a new project and add the following to "build.gradle". There is no build.gradle, so I added the following to "build.gradle.kts" and it doesnt work or give any meaningful errors.
Copy code
dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
...
}
The above just gives the error "Unexpected tokens (use ';' to separate expressions on the same line)" and I cant find anything about using or not using that online and it doesn't seem to exist. ive tried with and without ( ), ive tried looking up every combination of the above I could think of, I don't even know where to look.
j
Seems the book you are reading is out of date. The Kotlin Gradle plugin automatically adds a dependency on the Kotlin standard library, since Kotlin 1.4.
build.gradle is a Gradle build script using the Groovy language. build.gradle.kts uses Kotlin. Newer projects generated from recent wizards will usually prefer Kotlin. The syntax can differ slightly if you're reading examples in Groovy.
s
you can't call non-infix functions without parentheses, for one
j
The equivalent in Kotlin would be:
Copy code
dependencies {
    compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
...
}
But again, you shouldn't need to declare the standard library dependency explicitly with a recent version of Kotlin, like 1.9.21.
👆 2
v
And
compile
is deprecated since many many many years and was finally removed in 7.0. So unless you use an ancient Gradle version, even what @Jeff Lockhart showed will not compile as there is no
compile(...)
anymore unless you add it yourself or through some strange plugin.
If you want to follow that book, you should probably use the same ancient versions that book's author used, so that you get the expected results. But well, you will learn outdated information then. 🙂
💯 1
j
Also true. It's been so long since I've seen
compile
, I read it as
compileOnly
! You should replace
compile
here with
implementation
, or if you need to transitively share the dependency's API, use
api
. I'd probably recommend finding a newer edition of this book, or another newer resource to follow, so you're not learning outdated information.
e
Thanks everyone, @Jeff Lockhart @Vampire @Shawn - The book is Head First Kotlin, and attached is the section in reference. From my understanding, what you are saying is that 1. compile does not exist anymore in modern gradle and kotlin and serves no purpose 2. compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8" also doesn't do anything in the modern build process as the kotlin standard library doesn't need to be declared as a dependency 3. I don't need the outdated versions, this is the very end of the book and the first thing that I've found which hasnt worked after 700 pages, I'm pretty happy with the book it's been a useful crash course of Kotlin. 4. Trying to look up how to include coroutines in the gradle build just simply turns up nothing useful to me, I cant find any guides or references that involve gradle and kotlin, I have 0 idea what the gradle build script is supposed to do other than, obviously, build the project. Are there any useful guides, references, overviews to the gradle build script? I haven't been able to find any
v
1. ✅ 2. ✅ 3. ✅ 4.
Trying to look up how to include coroutines in the gradle build just simply turns up nothing useful to me
The page shows it, the bold line. It is just the Groovy DSL variant. For Kotlin, add parens around the string and use double-quotes. Also the coroutines readme has a Kotlin example: https://github.com/Kotlin/kotlinx.coroutines
Are there any useful guides, references, overviews to the gradle build script?
The Gradle user manual for example? https://docs.gradle.org/current/userguide/userguide.html
j
I would expect most of a book about Kotlin to still be relevant information. The language has mostly evolved to include more features, without deprecating or removing anything non-experimental. But an older book would lack information about the more recent language developments. Gradle as a build tool has definitely gone through some considerable changes though. The Kotlin website has good documentation for coroutines, Gradle, and all of the core language features.
e
Thank you both for your time, advice, and resources!
👌 1
j
You're welcome! Wish you the best on your Kotlin journey. It's a fun language and great community.
e
I would't say I've experienced a great community myself, aside from this slack - this slack has been great but all of the usual suspects for other languages I've looked for for kotlin and found crickets and cobwebs. Haven't checked reddit yet as that's not really my thing, but I've been unable to find any discords or IRC channels, and most searches come up empty, are actually just about java, or are just links to the kotlin documentation, which as far as documentation goes seems great but also in practice has been a little esoteric and inconsistent with my understanding. I'd love to find more community for this language, because I definately get the appeal - I mean any language that can get me to enjoy java really is just moving mountains in terms of language design
j
I can't speak for other corners of the internet, but there are a lot of smart, helpful Kotlin developers on this Slack. I think this is where most probably choose to spend their time. And JetBrains as an organization is quite accessible and connected with the community as well.