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

    James Hendry

    01/12/2022, 9:23 PM
    Hi im trying to translate something groovy/gradle to kotlin gradle. In the original groovy it would be done like so:
    reobfJar {
        shadowJar
    }
    I can't figure out how to do this in kotlin. reobfJar is a task. I want the reobfJar task to also be run on the shadowJar too. (not sure quite how this works unfortunately) The closest i've got i think is:
    tasks.all {
        println("Task $this, path ${this.path}")
        if (this.path == ":reobfJar") {
            println("I AM REOBFJAR!")
            this.configure<net.minecraftforge.gradle.patcher.tasks.ReobfuscateJar> {
                tasks.getByName("shadowJar")
            }
        }
    }
    I can't figure out how to get the reobfjar task without iterating, .getByPath doesn't seem to work. But also this.configure seems to want an Extension instead of a task? No clue what im supposed to do here.
    v
    • 2
    • 1
  • f

    FunkyMuse

    01/16/2022, 1:45 PM
    Hey guys, how to declare a function inside project build.gradle and use it inside app build gradle, it was possible with Groovy
    b
    v
    c
    • 4
    • 12
  • d

    dave08

    01/16/2022, 4:03 PM
    I don't know why I keep on getting mysterious errors in gradle like this:
    e: .../app/build.gradle.kts:10:45: Unresolved reference: util
    e: .../app/build.gradle.kts:11:65: Unresolved reference: newDataInputStream
    I updated to gradle 7.3.3 and android plugin 7.0.4...
    v
    • 2
    • 12
  • d

    dave08

    01/16/2022, 4:15 PM
    It seems like AndroidStudio's import suggestions don't work too well with gradle kts... and inlining the import doesn't work either...
    :thread-please: 2
    j
    • 2
    • 3
  • c

    Colton Idle

    01/16/2022, 11:25 PM
    I want to create a kotlin only library module in my android app. I went through and created it using the wizard and got this
    plugins {
        id("java-library")
        id("org.jetbrains.kotlin.jvm")
    }
    but then I went and looked at an old project and it had a kotlin only lib module that looked like this:
    plugins {
        id("java-library")
        id("kotlin")
    }
    So is there any diff between the second lines in both of these?
    v
    j
    f
    • 4
    • 5
  • k

    K Merle

    01/17/2022, 12:08 PM
    Stuck on
    :app:compileDebugUnitTestKotlin
    . Any help appreciated.
    v
    • 2
    • 3
  • l

    leandro

    01/17/2022, 6:11 PM
    using
    kotlin-multiplatform
    plugin, is it possible to create a sourceSet from a folder that’s sibling to the module that I’m currently configuring? As in, I have modules A and B, like so:
    moduleA
      test
      testShared
      build.gradle.kts
    moduleB
      test
      build.gradle.kts
    I would like to include
    testShared
    when running
    :moduleB:test
    What I have on moduleA:
    val jvmTestShared by creating
        val jvmTest by getting {
          dependencies {
            dependsOn(jvmTestShared)
          }
        }
    but I can’t seem to be able to create
    jvmTestShared
    on moduleB
    j
    v
    • 3
    • 19
  • l

    leandro

    01/17/2022, 6:25 PM
    Yes, I can move
    testShared
    anywhere, actually. It’s quite a unique setup because I can only run it on JVM targets, so even having one depending on the other might be tricky because ArchUnit does not know about
    kotlin-multiplatform
    plugin
    :thread-please: 1
    w
    v
    • 3
    • 8
  • t

    Travis Reitter

    01/18/2022, 6:55 PM
    hi! Sorry if this is a Groovy question but this is blocking me from migrating to Kotlin DSL. I'm trying to figure out how to call the
    create()
    function here from a Groovy gradle file. I've tried calling this way:
    cklib {
        create("sqlighter") {
            language "co.touchlab.cklib.gradle.CompileToBitcode.Language.OBJC"
        }
    }
    but I'm getting:
    org.gradle.api.GradleScriptException: A problem occurred evaluating project ':SharedCode'.
    ...
    Caused by: groovy.lang.MissingMethodException: No signature of method: build_89t0gtdiazmlot5b0npjl25b8.cklib() is applicable for argument types: (build_89t0gtdiazmlot5b0npjl25b8$_run_closure3) values: [build_89t0gtdiazmlot5b0npjl25b8$_run_closure3@7e7932ea]
    Possible solutions: mkdir(java.lang.Object), split(groovy.lang.Closure), wait(), file(java.lang.Object), wait(long), copy(groovy.lang.Closure)
    Here's a working example of it being called from Kotlin DSL. What simple syntax error am I making? 🙂
    h
    v
    • 3
    • 22
  • z

    Zahara Vidumshikova

    01/19/2022, 8:15 AM
    I have a code in lagacy style:
    buildscript {
        repositories {
            maven {
                url = uri("<https://files.minecraftforge.net/maven>")
            }
            mavenCentral()
        }
        dependencies {
            classpath("net.minecraftforge.gradle", "ForgeGradle", "5.+") {
                isChanging = true
            }
        }
    }
    How can I rewrite it into apply(plugin="smth") style? This does not work:
    repositories {
       maven(url = "<https://maven.minecraftforge.net>")
       mavenCentral()
    }
    
    apply(plugin = "net.minecraftforge.gradle:ForgeGradle:5.+")
    v
    g
    e
    • 4
    • 21
  • s

    Slackbot

    01/22/2022, 12:28 AM
    This message was deleted.
    :not-kotlin: 4
    v
    • 2
    • 1
  • i

    iamthevoid

    01/23/2022, 11:00 AM
    what is the best way to add git submodule sources to project? I want to submodule use own
    build.gradle(kts)
    files, but if i add it as
    project
    dependency (
    :path:to:submodule
    ) submodule use root project
    build.gradle(kts)
    files to build its sources and i must to synschronize build variables. It is kind of easy (but not normal) if i use own project as submodule, but what if i want to add any project and it has own gradle build architecture?
    e
    • 2
    • 2
  • j

    Justin Tullgren

    01/24/2022, 6:26 PM
    Hi does anyone know if this example works for kotlin projects or just java projects: https://docs.gradle.org/current/samples/sample_jvm_multi_project_with_additional_test_types.html Thanks!
    t
    • 2
    • 4
  • t

    tseisel

    01/30/2022, 12:56 PM
    Is it possible to apply specific Kotlin compiler arguments for an Android build variant ? I can configure arguments with
    tasks.withType<KotlinCompile>().configureEach {
      kotlinOptions {
        freeCompilerArgs = freeCompilerArgs + listOf(
          "-Xno-param-assertions",
          "-Xno-call-assertions",
          "-Xno-receiver-assertions"
        )
      }
    }
    but it's applied to all build variants, which is not what I want. The
    kotlin.android
    Gradle plugin creates compilation tasks (
    compileDebugKotlin
    ,
    compileReleaseUnitTestKotlin
    , etc) for each source set, but it seems there is no way to configure their
    kotlinOptions
    individually.
    p
    v
    • 3
    • 3
  • k

    Kiki Abdullah

    01/30/2022, 3:58 PM
    message has been deleted
    v
    • 2
    • 4
  • a

    Alessandro Tagliapietra

    01/30/2022, 6:04 PM
    Hi everyone, I have a project with a few dependencies (kafka, spring etc) and I'm trying to create a jar file for kafka connect with only my kafka connect relevant code and a single dependency. Since I'm already using shadow, I've tried to create the task like thi
    // Custom jars for kafka connect
    create<ShadowJar>("kafkaConnectUtilsJar") {
        archiveClassifier.set("connect-utils")
        include("co/visup/kafkaProcessor/connect/**")
        include("co/visup/kafkaProcessor/serializer/**")
        dependencies {
            include(dependency("io.confluent:kafka-connect-storage-partitioner:10.2.4"))
        }
        from(project.sourceSets.main.get().output)
        configurations = listOf(project.configurations.runtimeClasspath.get())
    }
    however while I see the classes in
    co/visup
    etc, I don't see the dependency, anyone has any idea?
    • 1
    • 1
  • a

    Alexander Black

    01/31/2022, 7:53 PM
    Hey all, I’m wondering if anyone has any learning resources they can share for Gradle? I’ve been programming Android apps for around 8 years now and still find Gradle to be one of the most challenging parts of my job and the area where I seem to waste a large amount of time. I think part of it is just not understanding the full extent of the tool. So if anyone has any books, blogs, video resources on the topic that helped them understand Gradle better I’d really appreciate it. 🙂
    m
    p
    • 3
    • 3
  • u

    ursus

    01/31/2022, 9:20 PM
    Why do I see multiple java processes even though I have the AS jdk and CLI point to same thing?
    v
    • 2
    • 2
  • m

    martmists

    02/01/2022, 2:56 PM
    How do I reduce the number of files generated by the publish task?
    p
    h
    +2
    • 5
    • 11
  • k

    Karlo Lozovina

    02/01/2022, 5:03 PM
    Using the latest Gradle and .kts build scripts, how can I specify compiler options for a custom sourceSet? For example, for main and test sourceSets it's:
    tasks {
        compileKotlin {
            kotlinOptions { ... }
        }
        compileTestKotlin {
            kotlinOptions {... }
        }
    }
    How would I specify options for some other buildSrc, let's call it "someOtherSrc"?
    b
    • 2
    • 7
  • j

    Jan

    02/02/2022, 5:46 PM
    Whats the best way to make a HTTP request in a custom task?
    v
    • 2
    • 3
  • k

    Karlo Lozovina

    02/03/2022, 4:37 PM
    I want to tweak JVM parameters for testing - is there a difference between
    tasks { test { jvmArgs = ...}}
    vs.
    tasks { withType<Test> { jvmArgs = ...}
    ? It seems to work identically, but is one way better than the other?
    f
    v
    j
    • 4
    • 4
  • e

    Eugen Martynov

    02/04/2022, 7:31 PM
    I see a lot of my CI kotlin compile (maybe all) are missing build cache. What can be the cause? (Sorry if it was answered already or there is no answer since information is not enough).
    t
    c
    • 3
    • 21
  • b

    brabo-hi

    02/05/2022, 8:06 PM
    Hi all, is there a tool to convert
    build.gradle
    to
    build.gradle.kt
    m
    t
    +2
    • 5
    • 7
  • j

    Jan Skrasek

    02/09/2022, 9:16 AM
    Hi, I'm trying to automatically add compiler opt-ins for all my modules (where it matters). But the "where it matters" is important, otherwise when the opt-in annotation is not available the build fails (as we utilize warning as errors). Zac's workaround is nice, but doesn't account for transitive dependency.
    configurations
        .configureEach {
          incoming.afterResolve {
            dependencies.forEach { dependency ->
              if (dependency.name == "eithernet") {
                tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
                  kotlinOptions {
                    @Suppress("SuspiciousCollectionReassignment")
                    freeCompilerArgs += "-Xopt-in=com.slack.eithernet.ExperimentalEitherNetApi"
                  }
                }
              }
            }
          }
        }
    I've spent two days resolving the transitive deps but still failing to do it properly anyhow. Any idea?
    v
    • 2
    • 1
  • e

    electrolobzik

    02/09/2022, 10:09 AM
    How does
    val answer: String by project
    work?
    Project
    interface doesn’t have
    getValue()
    and
    setValue()
    , so how does it work as a delegate then?
    ✅ 1
    s
    • 2
    • 13
  • u

    ursus

    02/10/2022, 1:40 AM
    Does it make sense to see more than 2
    java
    processes running? I presume 1 is for kotlin deamon, 2nd is for gradle daemon. But are 3, 4 necessary? They both seem to be pointing to gradle. Is this normal or possible a bug? (Since there are issues with new AS version not respecting the JDK path settings and using its own packages JRE etc; and no I’m not couting these in)
    e
    • 2
    • 2
  • g

    Goldcrest

    02/11/2022, 2:44 AM
    Hi, has anyone ran into trouble with gradle task
    :kaptGenerateStubsKotlin
    with
    java.lang.NoClassDefFoundError: Could not initialize class <http://org.jetbrains.kotlin.com|org.jetbrains.kotlin.com>.intellij.pom.java.LanguageLevel
    on JVM 17? I’m having a “it works on my machine” problem and the only difference seems to be the JVM version. We were able to amend it by adding gradle.properties settings option
    org.gradle.jvmargs=-Dkotlin.daemon.jvm.options=--illegal-access=permit
    , but it seems like out of random the build fails even with the option too, in which case we remove the option again-- as if the error switches on and off out of nowhere. Any hints would be appreciated! Thanks in advance!
    e
    r
    • 3
    • 5
  • m

    martmists

    02/12/2022, 1:14 PM
    I'm trying to split my build.gradle.kts into multiple files, but while the gradle script does run when split and using
    apply(from="/path/to/file.gradle.kts")
    , I don't seem to get any syntax highlighting or other IDA features. Is there a different way I should split gradle scripts?
    c
    n
    +2
    • 5
    • 8
  • d

    darkmoon_uk

    02/12/2022, 1:53 PM
    Weird Gradle behaviour regarding
    inline
    : I'm moving code out of my
    build.gradle.kts
    into extension functions on Android's
    LibraryExtension
    in
    buildSrc
    , making the config nice and neat 👍 After moving the code, it doesn't work 😱, Gradle behaves as though the config hasn't applied, even though the calls are there and it compiles. One of the things I tried out of desperation was to make the functions
    inline
    , and suddenly it all works!!! Never before have I come across a situation in Kotlin where
    inline
    changes behaviour 🤷 Oh Gradle... the tool that's guaranteed to keep me humble as a developer. Whenever I think I've finally understood it; you can be guaranteed a heavy fall is just around the corner.
    v
    • 2
    • 1
Powered by Linen
Title
d

darkmoon_uk

02/12/2022, 1:53 PM
Weird Gradle behaviour regarding
inline
: I'm moving code out of my
build.gradle.kts
into extension functions on Android's
LibraryExtension
in
buildSrc
, making the config nice and neat 👍 After moving the code, it doesn't work 😱, Gradle behaves as though the config hasn't applied, even though the calls are there and it compiles. One of the things I tried out of desperation was to make the functions
inline
, and suddenly it all works!!! Never before have I come across a situation in Kotlin where
inline
changes behaviour 🤷 Oh Gradle... the tool that's guaranteed to keep me humble as a developer. Whenever I think I've finally understood it; you can be guaranteed a heavy fall is just around the corner.
v

Vampire

02/12/2022, 2:08 PM
That's then maybe more a bug somewhere? Can you reproduce that behavior in an MCVE? Sounds pretty strange.
View count: 16