https://kotlinlang.org logo
Join the conversationJoin Slack
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
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
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
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 Linen
gradle
  • j

    Joey Heck

    10/12/2018, 4:30 PM
    I have a case statement inside one of my groovy file's plugins that uses a lambda I'm not sure how to reproduce in Kotlin
    appToken { ApplicationVariant variant ->
            switch (variant.buildType.name) {
                case 'develop': 'XXXX'
                    break
                case 'release': 'YYYY'
                    break
            }
        }
    How can I access the same specific ApplicationVariant? The only thing I could think of was to use
    android.applicationVariants.first()
    , but I get Build Failure error: Collection is empty.
    e
    • 2
    • 6
  • j

    jcechace

    10/14/2018, 9:32 AM
    Any idea how to make this
    build.gradle.kts
    work? What I need is esentially a kotlin-dsl gradle project with latest ktor
    g
    • 2
    • 8
  • n

    Nikky

    10/14/2018, 6:06 PM
    message has been deleted
    m
    • 2
    • 3
  • j

    jlleitschuh

    10/15/2018, 8:45 PM
    @Paul Woitaschek Hi,
    ktlint-gradle
    plugin author here. What are you actually trying to achieve here?
    p
    t
    • 3
    • 15
  • c

    CamilleBC

    10/16/2018, 9:29 AM
    Hello guys! I've been trying to setup kotlin 1.3rc in my project. I've been in Tools -> kotlin -> Configure Kotlin Updates and activated
    Early Access Preview 1.3
    . My project build.gradle has
    buildscript {
        ext.kotlin_version = '1.3.0-rc-146'
        repositories {
            google()
            jcenter()
            maven { url '<https://dl.bintray.com/kotlin/kotlin-eap>' }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.2.1'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    But I cannot resolve this line in my app build.gradle:
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    It fails with the following message:
    Failed to resolve: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.0-rc-146
    Do you now how to implement the stdlib for kotlin in the gradle file? I've been to MVN repository (https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib/1.3.0-rc-146) and used their gradle line. It still displays
    Failed to resolve: org.jetbrains.kotlin:kotlin-stdlib:1.3.0-rc-146
    . Help? 😄
    n
    • 2
    • 2
  • n

    Nikky

    10/16/2018, 9:32 AM
    i'd still suggest to switch to the plugins block because gradle can cache the loaded pugins and know more about what is loaded, can generate accessors and the like
    c
    • 2
    • 1
  • n

    Nikky

    10/16/2018, 1:27 PM
    it simplifies buildscripts a lot and learning how to move constants and functions into
    buildSrc
    also helps with that
    d
    • 2
    • 4
  • j

    jmfayard

    10/16/2018, 1:41 PM
    good thanks!
    g
    • 2
    • 8
  • j

    jmfayard

    10/16/2018, 1:48 PM
    What I would like to see (and contribute to!) is a a list of the most popular gradle plugins that would be something like this
    g
    • 2
    • 2
  • d

    Dias

    10/16/2018, 3:41 PM
    buildscript {
        repositories {
            jcenter()
            maven { url "<https://packages.dns.ad.zopa.com/artifactory/maven-libs-virtual>" }
        }
        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.71"
        }
    }
    m
    • 2
    • 2
  • r

    ribesg

    10/18/2018, 10:32 AM
    How do you define a function in
    kotlin-dsl
    ? IntelliJ keeps saying my function has no body
    g
    • 2
    • 2
  • r

    rocketraman

    10/19/2018, 4:53 AM
    Figured it out: a plugin was doing some config based on CI=true (turning off snapshot caching) but in the after evaluation block, which seems to conflict with kotlinScriptDef -- moving the setting to outside the after eval block fixed it.
    t
    • 2
    • 2
  • e

    enleur

    10/19/2018, 9:04 AM
    trying to change source sets for kotlin, is this the best way to do it? UPD
    val SourceSet.kotlin: SourceDirectorySet
        get() = withConvention(KotlinSourceSet::class){ kotlin }
    
    sourceSets {
        getByName("main") {
            kotlin.srcDirs("src")
            resources.srcDirs("resources")
        }
    
        getByName("test") {
            kotlin.srcDirs("test")
            resources.srcDirs("testresources")
        }
    }
    e
    • 2
    • 2
  • j

    jmfayard

    10/19/2018, 11:32 AM
    Have you ever wanted to write an extension fonction like
    fun  Project.doSomethingCool()
    that would also works in a Groovy
    build.gradle
    file? Have a look at this pattern:
    project.kt.doSomethingCool()
    https://github.com/jmfayard/gradledemo/commit/896ea008fea9d792d69dad122addc76d09ebce54
    🇳🇴 1
    n
    • 2
    • 4
  • j

    JoeHegarty

    10/19/2018, 8:58 PM
    I assume I can write a Gradle plugin in Kotlin? I notice the
    KotlinBasePluginWrapper
    is in Kotlin but obviously the majority of plugins are Groovy. Are there any gotchas? Specifically around the fact that I assume Kotlin is already in the classpath in Gradle due to the DSL? Are there any lightweight examples of how to set up a project for this?
    m
    • 2
    • 1
  • j

    Johan Vergeer

    10/20/2018, 10:23 AM
    Hi all, I’m running into some challenges while trying to create integration tests using Gradle Kotlin DSL. I already just posted a question on StackOverflow. But I hope someone here can help me out with this one. https://stackoverflow.com/questions/52904603/integration-tests-with-gradle-kotlin-dsl
    n
    e
    • 3
    • 29
  • z

    zachtib

    10/20/2018, 12:30 PM
    this is the source file inside buildSrc. From what I can tell, it should compile, but I get an error that "compile" can't be found
    utils_kt.kt
    g
    • 2
    • 8
  • p

    Paul Woitaschek

    10/21/2018, 7:16 AM
    How can I do that for debug builds only?
    t
    • 2
    • 5
  • n

    Nikky

    10/21/2018, 12:48 PM
    i see.. what should i do for a multi module project ? i want to not redeclar adependencies in every module but i also do not want to leak them fro mthe library
    g
    j
    • 3
    • 18
  • d

    dsvoronin

    10/22/2018, 1:13 PM
    like that:
    pluginManagement {
        resolutionStrategy {
            eachPlugin {
                if (requested.id.id.startsWith("org.jetbrains.kotlin")) {
                    useVersion(kotlinVersion)
                }
            }
        }
    }
    j
    • 2
    • 1
  • d

    dsvoronin

    10/22/2018, 1:16 PM
    not sure if buildSrc classpath accessible in
    settings.gradle.kts
    g
    • 2
    • 1
  • j

    jcechace

    10/22/2018, 1:17 PM
    I really don’t see the reason to use buildSrc just to use a variable (I don’t need any more complex build logic — which if I understand correctly is what buildSrc is for)
    g
    • 2
    • 1
  • e

    eskatos

    10/22/2018, 6:13 PM
    @dsvoronin how timely, I just wrote this https://builds.gradle.org/repository/download/Gradle_Check_BuildDistributions/16892087:id/distributions/gradle-5.0-all.zip%21/gradle-5.0-20181022184542%2B0200/docs/userguide/kotlin_dsl.html#troubleshooting
    j
    d
    • 3
    • 21
  • n

    Nikky

    10/23/2018, 9:46 AM
    @nikolaymetchev please see https://spekframework.org/migration/
    n
    • 2
    • 4
  • d

    dsvoronin

    10/23/2018, 12:50 PM
    Got some really weird state with script dep’s resolving:
    org.gradle.tooling.BuildException: Could not fetch model of type 'KotlinBuildScriptModel' using Gradle installation '/Users/dsvoronin/.gradle/wrapper/dists/gradle-4.10.2-bin/em75h4kbtmi6i8f32m058ve4q/gradle-4.10.2'.
    …
    Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method api() for arguments [com.adjust.sdk:adjust-android-criteo:4.15.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
    rewriting groovy script to kts in fact solves issue! but thats weird, i have alots of groovy scripts in project (150+)
    e
    m
    • 3
    • 36
  • d

    dagguh

    10/23/2018, 3:58 PM
    where's the changelog/source of the Kotlin Gradle Plugin? Standard locations like the Maven Central entry (https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin/1.2.70) or Gradle plugin portal (https://plugins.gradle.org/plugin/org.jetbrains.kotlin.jvm/1.2.70) simply refer to kotlinlang.org, which doesn't really help
    i
    • 2
    • 1
  • b

    breandan

    10/24/2018, 7:33 AM
    Some feedback having used the Kotlin DSL for a while: it's very easy to migrate boilerplate applications, but if you use any kind of plugin the process is very cumbersome. I recently wanted to use the
    org.jetbrains.gradle.plugin.idea-ext
    plugin, which required a bunch of trial and error to translate (and the result does not look very natural). Are plugin authors expected to make their API Kotlin DSL friendly, or is there some kind of migration process planned? This was the result: https://github.com/acejump/AceJump/blob/6d06723fc5f590e0b75ea78d260c7f23bc3b87aa/build.gradle.kts#L28:L41
    g
    • 2
    • 1
  • o

    octylFractal

    10/24/2018, 7:37 AM
    runConfigurations
    looks like it should extend one of Gradle's standard named collections, and the DSL adds special overrides for that, you should be able to do something like
    create<...Application>("runIde") { ...
    if it does
    👍 1
    b
    • 2
    • 2
  • b

    breandan

    10/24/2018, 7:43 AM
    I understand they didn't want to use the same DSL in Kotlin as Groovy, but there's a bunch of extra ceremony for using the Kotlin DSL right now
    g
    n
    • 3
    • 22
  • j

    jmfayard

    10/24/2018, 9:38 AM
    Looking at a complete example of what it looks like to convert a project to from Groovy to Kotlin? Have a look at what I did here https://github.com/rozkminiacz/KotlinUnitTesting/pull/2
    g
    • 2
    • 2
Powered by Linen
Title
j

jmfayard

10/24/2018, 9:38 AM
Looking at a complete example of what it looks like to convert a project to from Groovy to Kotlin? Have a look at what I did here https://github.com/rozkminiacz/KotlinUnitTesting/pull/2
g

gildor

10/24/2018, 10:26 AM
I added a few comemnts
j

jmfayard

10/24/2018, 10:34 AM
I have seen thanks, will have a look later
View count: 3