https://kotlinlang.org logo
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
benchmarks
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
confetti
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
lincheck
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by
Title
g

ghedeon

08/14/2019, 8:55 PM
Is it possible to write tasks in Kotlin in buildSrc, without migrating to DSL?
:yes: 3
m

mbonnin

08/14/2019, 9:02 PM
Yes, it should work fine.
g

ghedeon

08/14/2019, 9:09 PM
hm. It's highlighted, but it stops working after I convert it to Kotlin. Ex: Java
package com.foo;

public class Fun {
  public static void sayHello() {
    System.out.println("Hello");
  }
}
Usage:
task hello {
    doLast {
        com.foo.Fun.sayHello()
    }
}
That works. Once I convert
Fun
to kotlin it can't import it anymore.
m

mbonnin

08/14/2019, 10:05 PM
Did you configure kotlin in
buildSrc/build.gradle
?
g

ghedeon

08/14/2019, 10:10 PM
yes, like this:
plugins {
    kotlin("jvm") version '1.3.31'
}

dependencies {
    implementation gradleApi()
    compile(kotlin("stdlib-jdk8"))
}
g

gildor

08/14/2019, 11:09 PM
You don't need Kotlin Plugin, it already bundled to Gradle, but you may use kotlin-dsl plugin which configures gradleApi, stdlib and uses bundled versions of it:
plugins {
   id "org.gradle.kotlin.kotlin-dsl" version "1.2.10"
}
Check that your import is correct (maybe you need something like com.too.FunKt or Companion, depends on how your final code looks like), check that this file in buildSrc/src/kotlin, not in src/groovy
k

kingsley

08/15/2019, 8:09 AM
Also, might be possible that you’re missing
@JvmStatic
on that method, so the Groovy buildscript doesn’t see it as a static
Fun.sayHello()
anymore
g

gildor

08/15/2019, 8:35 AM
yes, it depends what is final kotlin code
g

ghedeon

08/16/2019, 11:25 AM
@gildor you mean to mirgate buildSrc to kotlin-dsl? Or just applying the dsl plugin in
build.gradle
? Because the later gives me
NoClassDefFoundError: org/gradle/kotlin/dsl/support/KotlinDslPluginsKt
g

gildor

08/16/2019, 11:26 AM
Just apply Kotlin DSL plugin to buildSrc project
Anyway, it's not requirement, just simplifies configuration and provide a lot of Kotlin DSL helpers for work with Gradle API from kotlin
Looks that this version of Kotlin DSL not compatible with your gardle version, unfortunately there is no easy way to consume this plugin to match Gradle, you can check requires Kotlin DSL version in your Gradle distribution sources, but don't remember how to do that exactly. Because if you use kotlin-dsl for build.gradle, you have convinient accessor for this plugin. I created an issue about it, to simplify usage of kotlin-dsl plugin from Groovy code, but it's not fixed, as I remember
g

ghedeon

08/16/2019, 11:30 AM
well, didn't work, as I mentioned the error. Even without going dsl path, let's take a simple case: /buildSrc/src/main/kotlin/Dependencies.kt
object deps {
    val multidex = "androidx.multidex:multidex:2.0.1"
}
I expect this to be visible in any of my
build.gradle
files as
implementation deps.multidex
. But it's not...
l

louiscad

08/16/2019, 11:42 AM
@ghedeon Which Android Studio version are you using? FYI, 3.3 and 3.4 broke buildSrc referencing from groovy based
build.gradle
scripts, but it is fixed in 3.5 now in RC. (That bug kicked-off my migration to Gradle Kotlin DSL)
g

ghedeon

08/16/2019, 11:45 AM
AS 3.4.2 😬
l

louiscad

08/16/2019, 11:53 AM
Then, install 3.5 RC3 aside, and open the project with it (no need to update AGP)
g

ghedeon

08/16/2019, 11:57 AM
just did it. Still doesn't work but at least I've got imports recognized by IDE. So, clicking on
deps.foo
actually brings you to your kotlin file in buildSrc. I'm wondering what people that answered "YES" do...
l

louiscad

08/16/2019, 12:11 PM
They replied regarding theory, but at least two of them are using Gradle Kotlin DSL and dropped dynamic syntax.
m

mbonnin

08/16/2019, 12:40 PM
@ghedeon an example of using a kotlin buildSrc with build.gradle files: https://github.com/HearthSim/Arcane-Tracker/tree/bdf01d728d5eddefba68f76e5da155620f480d00/buildSrc
g

gildor

08/16/2019, 12:47 PM
I expect this to be visible in any of my
build.gradle
files as
implementation deps.multidex
. But it's not...
Why do you expect that it will work? Groovy is not Kotlin, you have to use Java syntax, something like:
deps.INSTANCE.getMultidex()
, or use JvmStatic instead
m

mbonnin

08/16/2019, 12:51 PM
Or make
multidex
const ?
I have this,
object Libs {
    const val supportLibVersion = "28.0.0"
}
Kotlin bytecode shows:
public final class Libs {


  // access flags 0x19
  public final static Ljava/lang/String; supportLibVersion = "28.0.0"
  @Lorg/jetbrains/annotations/NotNull;() // invisible
g

gildor

08/16/2019, 12:55 PM
yeah, you right! It will work with object
👍 1
g

ghedeon

08/16/2019, 1:07 PM
@gildor Irrelevant. Groovy recognizes that, even without const
g

gildor

08/16/2019, 1:07 PM
recognize Kotlin Object?
g

ghedeon

08/16/2019, 1:08 PM
yes
g

gildor

08/16/2019, 1:08 PM
what doesn’t work than in your case?
g

ghedeon

08/16/2019, 1:08 PM
well, you won't belive me... but apparently lower case name of the class
motherfucking flying bag of dicks. 2 days.
object deps
-->
object Deps
g

gildor

08/16/2019, 1:12 PM
maybe just some name conflict?
What kind error did you have?
g

ghedeon

08/16/2019, 1:12 PM
same for Libs and libs
g

gildor

08/16/2019, 1:12 PM
what abou SomethingRandom and somethingrandom? %)
g

ghedeon

08/16/2019, 1:12 PM
that
deps
does't exists
g

gildor

08/16/2019, 1:13 PM
Groovy 🤷‍♂️
g

ghedeon

08/16/2019, 1:14 PM
same for somethingrandom. They are for real
if it's not ridiculous enough, in my side project with kotlin dsl lower case is not a problem. So, it's just this weird combination of groovy and kotlin
was nice knowing you guys, for all these years. I think I give up on android. 👋
g

gildor

08/16/2019, 1:17 PM
Not really related on Android tho 😬
☝️ 2
g

ghedeon

08/16/2019, 1:24 PM
disagree. It's an essential part of the android development. They brought gradle to android in 2013-2014? 5 years later terrible support in IDE, constant breaking changes, incompatibilities, performance issues, etc. It's an everyday struggle.
l

louiscad

08/16/2019, 1:26 PM
If you use gradle the default simple way, with no third-party plugins, it just works.
1
You're putting code into the build script itself. Understandable Google folks didn't expect this at first. Kotlin wasn't still in early, early stages, mostly unknown.
g

gildor

08/16/2019, 1:28 PM
It’s an essential part of the android development
Yeah, same as huge amount of other technologies, and at least Gradle can be avoided if you really know what are you doing