https://kotlinlang.org logo
Docs
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
  • s

    Shan

    01/26/2020, 2:16 AM
    I am adding it like so:
    repositories {
        maven(url = "<https://maven.jetbrains.space/[my-org]/[my-repo]>")
    }
    s
    • 2
    • 2
  • r

    Ran Magen

    01/26/2020, 5:26 AM
    One more groovy -> kts question. before, with groovy, for the Copy task's
    expand
    function, we passed in a map where a key contained a function value:
    [ pick: { Map<String, Object> stackMap, Object fallback -> stackMap.getOrDefault(stack, fallback) } ]
    The template file we copied had stuff like:
    replicas: ${pick(1, 'staging': 2, 'prod': 9)}
    Now that I've converted the groovy code (in the build file, not the template) to Kotlin script and it now looks like
    val pick = { stackMap: Map<String, Any>, fallback: Any -> stackMap.getOrDefault(stack, fallback) }
    and I pass in to `expand`:
    expand(mapOf("pick" to pick))
    expansion fails saying this:
    groovy.lang.MissingMethodException: No signature of method: Build_gradle$pick$1.call() is applicable for argument types: (LinkedHashMap, Integer) values: [[staging:2, prod:9], 1]
    If possible, what's the right way to pass a function in
    expand
    properties?
    • 1
    • 1
  • t

    thanksforallthefish

    01/27/2020, 5:23 PM
    hello, sometimes intellij complains about my kotlin dsl script, though gradle then execute correctly. for instance
    plugins {
      id("org.hidetake.swagger.generator") version  "2.18.1"
    }
    
    tasks {
      withType<org.hidetake.gradle.swagger.generator.GenerateSwaggerUI> {
        dependsOn("openapi3")
        inputFile = file("$buildDir/api-spec/openapi3.json")
      }
    }
    org.hidetake.gradle.swagger.generator.GenerateSwaggerUI
    is red, causing then
    dependsOn
    and
    inputFile
    to be not recognized
    d
    • 2
    • 6
  • r

    Ray Eldath

    01/28/2020, 12:54 PM
    hey everyone. are there any way to escape
    $
    when dealing with string
    ? currently I have to write something like
    "${'$'}argon2i${'$'}v=19${'$'}m=65536,t=10,p=1${'$'}JAqVeeNXYjPzqQxYOuek9w${'$'}bV2xPVMnPsV36LesGvM/yUDaisR3Bugn9wneiCPMnBY"
    which is absolutely very ugly 🙃
    b
    t
    • 3
    • 3
  • t

    tylerwilson

    01/28/2020, 10:14 PM
    Question: I have a Korlin/JS project that uses settings.gradle.kts and build.gradle.kts and a shared multiplatform project I would like to reference that is using settings.gradle and build.gradle (groovy). Is it possible to reference one from the other, or will I have to convert one to kts or the other to groovy?
    c
    • 2
    • 2
  • b

    Brendan Weinstein

    01/29/2020, 12:55 AM
    I want to apply the kotlinx plugin within the build.gradle.kts for
    buildSrc
    (eg use a plugin for the development of plugins), but I am getting this error:
    Plugin [id: 'kotlinx-serialization'] was not found in any of the following sources:
    Anyone know how to make a non-core plugin available within the buildSrc build.gradle.kts?
    d
    • 2
    • 2
  • n

    napperley

    01/29/2020, 2:03 AM
    Is it possible with the Gradle Kotlin DSL to run a process via SSH?
    d
    • 2
    • 7
  • m

    Moritz Platt

    01/29/2020, 11:09 AM
    Is it safe to use multiple versions of
    org.jetbrains.kotlin:kotlin-gradle-plugin
    in a Gradle multi-project build?
    s
    • 2
    • 3
  • s

    Sam Garfinkel

    01/29/2020, 4:31 PM
    Is there a workaround for the
    Calling non-final function 'function' in constructor
    warning when configuring subclasses of Gradle tasks? For example:
    open class ChildJavaExec: JavaExec() {
        init {
             workingDir("foo/bar")
        }
    }
    Not sure if I should just ignore it? Tasks need to be non-final in order for Gradle to inject and construct them.
    c
    • 2
    • 2
  • s

    Sagar Suri

    01/30/2020, 4:41 AM
    Is there any good source to learn about
    gradle
    build system w.r.t android?
    c
    • 2
    • 1
  • a

    Artem Shumidub

    01/30/2020, 6:24 AM
    Hello, maybe somebody here could help with it https://kotlinlang.slack.com/archives/C0B8M7BUY/p1580216453085700
    s
    • 2
    • 3
  • h

    Harun

    01/31/2020, 6:38 AM
    Hello everyone, is there a way after converting ..gradle files to kts in Android Studio to set consecutive modules setup to always use kts. I have seen that creating new modules also re-creates the gradle files even the ones that are there eg build.gradle(app module level) and settings.gradle
    f
    • 2
    • 2
  • j

    Jamie Taylor

    01/31/2020, 11:01 AM
    Can anyone help me figure out why my project takes so long to build? There seem to be two problems: 1. Incremental builds aren't working for kotlin. I made a dummy class containing no code that isn't referenced anywhere and if I add a line break to it then when I run ./gradlew assembleDebug every single kotlin file is recompiled. I'm basing that on the fact that according to the gradle build scan the compileDebugKotlin task takes as long as it does for a clean build. Java incremental builds seem to be working fine. The projct doesn't contain kapt, the only anotation processor is android databinding and in the gradle.properties we have:
    kotlin.caching.enabled=true
    org.gradle.caching=true
    android.databinding.incremental=true
    2. The Kotlin compiler is just really slow. The project is about 90% Java and 10% Kotlin, but on a clean build the Kotlin compile task takes about twice as long as the java compile task. The project also has a very small pure kotlin module containing three small files, and I just noticed on the scan that the kotlin compile task for that project is taking even longer than the kotlin compile for the main app. I can't find any particularly helpful resources regarding kotlin compiler performance. If I could just see which files it was spending a lot of time on that might help.
    t
    c
    n
    • 4
    • 8
  • k

    Kris Wong

    01/31/2020, 3:05 PM
    i am trying to create (register) a gradle task that modifies the configuration, but I only want this to happen when the task itself is executed. how can I achieve this?
    android.defaultConfig.testInstrumentationRunnerArguments.remove 'notClass'
            android.defaultConfig.testInstrumentationRunnerArguments 'class': 'com.boxer.sendHarness.SendMessageHarness'
    t
    • 2
    • 17
  • a

    Alex Woods

    01/31/2020, 3:20 PM
    Hey there guys! We’re making an architecture decision at my company—should we use Groovy or Kotlin for Gradle? What are the strong and weak points of the Kotlin DSL for Gradle?
    e
    r
    +4
    • 7
    • 7
  • d

    Dariusz Kuc

    02/01/2020, 1:41 AM
    hello! I would like to create some custom integration test using Gradle but unsure if that is possible - basically I need to: • start up 2 Spring Boot apps (graphql servers) • once they are up - start node app (graphql gateway) • once everything is up post HTTP request to the node app and verify response • stop all apps I know this most likely would be pretty messy but would love to run such integration test during our CI to ensure the libraries used by SpringBoot apps produce valid results that can be consumed by the node app. Alternative would be to the same with Github Actions but unsure if single action can spawn multiple processes. Any suggestions?
    c
    s
    • 3
    • 4
  • j

    jmfayard

    02/03/2020, 6:24 AM
    I submitted a PR to an Android sample to convert the Gradle build to Kotlin. There is an interesting discussion going on there I'm curious what happens next 🙂 https://github.com/android/camera-samples/pull/162
    :kotlin: 1
    g
    • 2
    • 4
  • t

    tseisel

    02/03/2020, 10:47 AM
    Hi everyone, I just created a new project with Kotlin Gradle scripts. I have a property defined in
    gradle.properties
    :
    com.foo.myproperty=bar
    What is the idiomatic way to read that property from scripts ? The property delegate syntax
    val myProperty by project
    makes it mandatory to declare a variable with the same name as the property. Moreover, it seems that there is no
    settings.property("com.foo.myproperty")
    function.
    c
    g
    +2
    • 5
    • 4
  • c

    Chenn

    02/04/2020, 8:08 AM
    Hello there, I'm sorry for the weird timing, but I'm based in Europe. I'm trying to get a Kotlin-Gradle-NPM project going, but I got a little confused with the (outdated?) documentation on the kotlinlang website. I've looked at the release notes for 1.3.5 and 1.3.6 and those gave me a bit more guiding, but I still remain uncertain as to how I can check if Gradle downloaded all the npm packages (if at all). An important not is that I'm trying to build a web interface for embedded and not an android app.
    b
    • 2
    • 1
  • t

    tarek

    02/05/2020, 10:06 PM
    How would you convert this snippet to
    kts
    ?
    allprojects {
      if (plugins.hasPlugin("org.jetbrains.kotlin.jvm")) {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
      }
    
      plugins.withId("com.android.library") {
        extensions.getByName("android").compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_8
          targetCompatibility JavaVersion.VERSION_1_8
        }
      }
    }
    d
    • 2
    • 5
  • m

    Marcelo Adamatti

    02/06/2020, 6:44 PM
    need help: did you guys have this issue caching gradle plugins with docker? https://www.reddit.com/r/gradle/comments/ezvqc5/gradle_docker_springboot_kotlin/ any guess?
    t
    p
    • 3
    • 10
  • d

    Dariusz Kuc

    02/07/2020, 2:57 AM
    hello, i'm trying to define custom gradle task that accepts output file name and generates corresponding output file according to some logic, e.g.
    @Input
    @Option(option = "outputFileName", description = "target file name")
    val outputFileName: Property<String> = project.objects.property(String::class.java)
    
    @Suppress("UnstableApiUsage")
    @Internal
    @OutputFile
    val outputFile: RegularFileProperty = project.objects.fileProperty()
    How do I properly initialize the
    outputFile
    with the specified
    outputFileName
    ?
    o
    • 2
    • 53
  • j

    Javier

    02/10/2020, 1:19 AM
    I am trying to import kotlin serialization via buildSrc gradle file but I cant get it working
    d
    e
    • 3
    • 8
  • s

    sean

    02/10/2020, 2:01 AM
    I'm probably missing it in the docs. But is there a way to get xml reports from kotlin multiplatform tests? I have an html output, but am trying to get xml for CI/CD?
    • 1
    • 1
  • n

    Nikita Khlebushkin

    02/10/2020, 3:03 PM
    Hello! I have a Kotlin compiler plugin in my MPP project that behaves as Annotation Processor (because Annotation Processors doesn't work on MPP according to

    https://youtu.be/w-GMlaziIyo?t=118▾

    ). I also have a Gradle Plugin that wraps my plugin, which eventually is used in my main module. It all works nice and smoothly, BUT: I need the plugin to be run before compiling the main project. I was wondering whether I can have something like
    compile.dependsOn(something)
    , but I don't know what task should I put in the parenthesis (I don't create explicitly any tasks)
    f
    • 2
    • 16
  • j

    jk2018

    02/10/2020, 11:02 PM
    Hi, can someone point me to a up-to-date Android stub project with the latest Kotlin with a build.gradle.kts , ideally with a few modules set up ?
    m
    o
    • 3
    • 19
  • a

    apahl

    02/11/2020, 2:38 PM
    Hi, I have worked with statically typed languages before, but have no prior Java / JVM experience. Therefore the hardest part in learning Kotlin for me is actually the Gradle build system, which (IMO) requires extensive JVM knowledge to understand it. Are there any Gradle Kotlin DSL (
    .gradle.kts
    build files) tutorials available that do not require such a Java / JVM background? I am exploring Kotlin mainly for Data Science purposes.
    c
    c
    • 3
    • 4
  • c

    corneil

    02/11/2020, 3:04 PM
    As a long time Gradle user I can tell you that Gradle Kotlin DSL kicks my butt often. The Gradle Groovy DSL is easier for me and there is still a huge amount of documentation and tutorials around that.
    👎 4
    👍 3
    g
    j
    • 3
    • 3
  • t

    Tmpod

    02/12/2020, 7:33 PM
    Hey there! Probably a dumb question, but I've never tried Kotlin's EAPs and I'm having some trouble getting the latest 1.3.70 EAP to work (EAP 184). My buildscript looks like this
    group = "..."
    version = "..."
    description = "..."
    
    object DependencyVersions {
        ...  // just a bunch of const strings for versions
    }
    
    plugins {
        kotlin("jvm") version "1.3.70-eap-184"  // afaik this block doesn't see DependencyVersions, so versions gotta be put manually here ig...
        application
    }
    
    repositories {
        ...  // bunch of repos
        maven("<https://dl.bintray.com/kotlin/kotlin-eap>")
    }
    
    dependencies {
        implementation(kotlin("stdlib"))  
        ...  // more deps
    }
    
    tasks {
        compileKotlin {
            ...  // I add some compiler args here
        }
    }
    
    application {
        mainClassName = "..."
    }
    with this said, Gradle can't find any kotlin version that satisfies what I've specified
    o
    g
    • 3
    • 12
  • s

    Sylvain Patenaude

    02/12/2020, 10:12 PM
    Are there some plugins more "standard" (or widely adopted) to publish libraries (.jar or .framework) to a Maven repository (such as mavenCentral or jcenter)? It looks that there are several existing ones.
    m
    o
    +3
    • 6
    • 9
Powered by Linen
Title
s

Sylvain Patenaude

02/12/2020, 10:12 PM
Are there some plugins more "standard" (or widely adopted) to publish libraries (.jar or .framework) to a Maven repository (such as mavenCentral or jcenter)? It looks that there are several existing ones.
m

mbonnin

02/12/2020, 10:13 PM
You want to look into the
maven-publish
gradle plugin
➕ 1
It can do bintray and sonatype and it's the most up-to-date AFAIK
o

octylFractal

02/12/2020, 10:13 PM
yes,
maven-publish
is the general standard
for publishing to central specifically, I use
nexus-publish
to ensure it works properly: https://github.com/marcphilipp/nexus-publish-plugin
m

mbonnin

02/12/2020, 10:15 PM
I was going to mention https://github.com/vanniktech/gradle-maven-publish-plugin too. I think this one creates the javadoc/sources artifacts automatically (which
maven-publish
doesn't do AFAIK)
f

Fleshgrinder

02/12/2020, 10:45 PM
Calling
withSourcesJar()
and
withJavadocJar()
isn't much work.
g

gildor

02/12/2020, 11:30 PM
Yes, but it will not work for Android (which is the main target of this library)
👍🏻 1
d

Dariusz Kuc

02/13/2020, 12:40 AM
having gone through that recently (i.e. publishing multi module Kotlin project to Maven Central using Gradle) I ended up with using •
maven-publish
to publish artifacts to the Maven Central •
signing
plugin to sign the artifacts •
de.marcphilipp.nexus-publish
for creating single staging repository in nexus •
io.codearte.nexus-staging
to ensure single staging repository is used for for all artifacts and automatically releasing it at the end Note that
maven-publish
will publish to nexus (each artifact ended up in its own staging repo) but it won't automatically release artifacts so in order to avoid manual step I added those 2 extra plugins.
Oh and we had to disable sha256 and sha512 checksums due to https://github.com/gradle/gradle/issues/11308
View count: 6