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
  • r

    René

    12/18/2019, 6:43 PM
    I'm not sure if this is an issue on the Kotlin or the Gradle side, however I'm facing the issue that I cannot read the source sets of the kotlin setup. Something has changed when I upgraded to Gradle 6.0 and my gradle plugin the source sets via
    project.convention.getPlugin(JavaPluginConvention::class.java.sourceSets
    n
    2 replies · 2 participants
  • u

    ursus

    12/21/2019, 12:47 AM
    Is there still a performance difference between groovy and kotlin dsl?
    t
    n
    +2
    13 replies · 5 participants
  • i

    Imran/Malic

    12/21/2019, 2:32 PM
    Is it possible to get the sourceSets given a project something like?:
    subProject { project ->
      def projectSourceSetClasspath = project.sourceSets.main.runTimeClassPath
    }
    t
    2 replies · 2 participants
  • c

    Clint Checketts

    12/23/2019, 11:55 PM
    I just upgraded from 5.2.1 to 6.0.1, using the Kotlin DSL and I had some code in my settings.gradle.kts that is now broken:
    rootProject.name = "example"
    
    val mavenUser: String by settings
    val mavenPassword: String by settings
    
    pluginManagement {
      repositories {
        maven {
          url = uri("<https://myrepo>")
          authentication { create<BasicAuthentication>("basic") }
          credentials {
            username = mavenUser
            password = mavenPassword
          }
        }
      }
    }
    s
    5 replies · 2 participants
  • j

    jdemeulenaere

    12/25/2019, 6:51 PM
    What's the suggested way to share constants between subprojects using the Gradle Kotlin DSL? (e.g. plugins or dependencies versions)
    n
    m
    +1
    3 replies · 4 participants
  • p

    pg

    12/29/2019, 1:38 PM
    Is it possible to write plugin, which 1) configure global config in root 2) use it in submodules with global config 3) override some specific options in concrete module ? I prefer to setup some common, default configuration in one place
    t
    g
    2 replies · 3 participants
  • v

    Vsevolod Kaganovych

    01/03/2020, 11:44 PM
    Guys, need your help. Trying to configure common gradle files for different modules in Android app. For example,
    version code
    and
    version name
    and then use it via
    apply
    . But when I try to enter
    android {}
    function, it says “cannot resolve reference”. Is there any way out?
    d
    3 replies · 2 participants
  • s

    Smith

    01/05/2020, 2:47 PM
    I have a multiproject gradle setup with Kotlin DSL. In my master build.gradle.kts I have:
    val someVersion: String by extra("1.2.3")
    However, in childproj/build.gradle.kts:
    val someVersion: String by extra
    does not work, saying “Cannot get non-null extra property ‘someVersion’” What’s the appropriate way to do variable inheritance?
    c
    n
    2 replies · 3 participants
  • n

    nrobi

    01/06/2020, 11:30 AM
    Hey! I’m trying to deploy my
    Ktor
    backend module from a
    KMP
    project to Heroku, but I’m getting
    A problem occurred configuring project ':app'.  > kotlin.KotlinNullPointerException (no error message)
    for
    Task :buildSrc:build
    . Anyone who had similar issues?
    n
    1 reply · 2 participants
  • n

    Nicholas Bilyk

    01/06/2020, 3:04 PM
    Hi, I've got a kotlin multi-platform multi-project build and I'm having trouble figuring out how to set the test reports output directory. I've tried (in my root build.gradle.kts):
    allprojects {
    	this.tasks.withType<TestReport> {
    		this.destinationDir = rootProject.buildDir.resolve("<mailto:reports/${this@allprojects.name|reports/${this@allprojects.name>}/")
    	}
    	this.tasks.withType<Test> {
    		this.reports.junitXml.destination = rootProject.buildDir.resolve("<mailto:reports/${this@allprojects.name|reports/${this@allprojects.name>}/xml/")
    		this.reports.html.destination = rootProject.buildDir.resolve("<mailto:reports/${this@allprojects.name|reports/${this@allprojects.name>}/html/")
    	}
    }
    But that doesn't seem to work. What's strange is that if I run clean / test repeatedly sometimes they end up where I'm declaring, but it's unreliable. It's as if I'm declaring this in the wrong spot.
    1 reply · 1 participant
  • j

    Joan Colmenero

    01/06/2020, 5:01 PM
    Can someone tell me why I can not use
    implementation project(':app')
    in my feature modules in Android?
    n
    3 replies · 2 participants
  • j

    Javier

    01/06/2020, 10:51 PM
    I updated Gradle to 6.0.1 and now in the root folder my settings.gradle.kts can't use my objects inside buildSrc... any way to fix it?
    o
    g
    6 replies · 3 participants
  • a

    Alessandro Tagliapietra

    01/07/2020, 1:56 AM
    HI there, is it possible to specify jvmTarget from command line during a gradle build?
    d
    1 reply · 2 participants
  • j

    jimn

    01/07/2020, 9:08 AM
    i dont want to add something to gradle that would fail on someone else's workstation there are working unit tests and gradle is happy with these. i cannot get kotlin-test or right click run <anything> from intellij
    g
    4 replies · 2 participants
  • b

    BorzdeG

    01/08/2020, 8:44 PM
    import org.gradle.api.Plugin
    import org.gradle.api.Project
    import org.gradle.jvm.tasks.Jar
    import org.gradle.kotlin.dsl.apply
    import org.gradle.kotlin.dsl.provideDelegate
    import org.gradle.kotlin.dsl.registering
    import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
    
    class PublishPlugin : Plugin<Project> {
        override fun apply(target: Project): Unit = target.run {
            apply<KotlinPluginWrapper>()
    
            val sourcesJar by tasks.registering(Jar::class){
                classifier = "sources"
            }
        }
    }
    Tell me what is wrong in the code? I get the error
    Type 'RegisteringDomainObjectDelegateProviderWithTypeAndAction <out TaskContainer, Jar>' has no method 'getValue (Nothing ?, KProperty <*>)' and thus it cannot serve as a delegate
    doing based on an example: https://github.com/gradle/kotlin-dsl-samples/blob/master/samples/maven-publish/build.gradle.kts
    o
    2 replies · 2 participants
  • d

    Dariusz Kuc

    01/10/2020, 9:55 PM
    hello, is there a way to share common properties between composite builds? e.g. given
    rootA
    - build.gradle.kts
    - gradle.properties <-- share this
    - settings.gradle.kts
    - libA
    - libB
    - pluginA
    - rootB
      - build.gradle.kts
      - settings.gradle.kts
      - exampleA (uses libA/libB and pluginA)
    Is there a way to share
    rootA/gradle.properties
    with
    rootB
    project?
    o
    d
    10 replies · 3 participants
  • j

    joe

    01/12/2020, 12:57 AM
    hey guys I have a jvmtarget 11 build that fails with the following stack trace (in thread), any ideas how do I debug it?
    d
    2 replies · 2 participants
  • d

    Dominaezzz

    01/12/2020, 5:48 PM
    How do you specify a classifier when declaring a project dependency?
    implementation(project(":sibling"), classifier = "natives-linux")
    doesn't work.
    o
    2 replies · 2 participants
  • t

    tapchicoma

    01/15/2020, 1:33 PM
    Is there a way to disable this warning?
    w: Language version 1.4 is experimental, there are no backwards compatibility guarantees for new language and library features
    e
    7 replies · 2 participants
  • s

    Sylvain Patenaude

    01/15/2020, 4:44 PM
    Anyone would know how to remove this warning:
    sourceSets {
        commonMain {
            dependencies {
                implementation kotlin("stdlib-common")
            }
        }
    The warning is:
    'kotlin' cannot be applied to '(java.lang.String)'
    .
    g
    o
    8 replies · 3 participants
  • d

    Dariusz Kuc

    01/15/2020, 11:42 PM
    hello, i'm trying to create maven
    pom.xml
    using
    maven-publish
    plugin but having trouble setting up the
    description
    , i.e. my project structure is
    root
    \- moduleA
    \- moduleB
    both
    root
    and modules contain their own
    build.gradle.kts
    files where i set their descriptions yet when I try to read them in
    [root] subprojects{}
    their all descriptions turn out empty. Any ideas?
    5 replies · 1 participant
  • j

    jkbbwr

    01/16/2020, 1:58 PM
    I need help writing a gradle task. I have an automated process that dumps out a directory like this
    ├── c_v_b_ce_one.h
    ├── c_v_b_ce_two.h
    ├── c_v_b_ce_three.h
    ├── c_v_b_ce_four.h
    ├── c_v_b_cl_five.h
    ├── c_v_b_cr_six.h
    ├── c_v_b_cr_seven.h
    ├── c_v_b_cr_eight.h
    ├── c_v_b_cr_nine.h
    ├── c_v_b_cr_ten.h
    ├── c_v_b_cr_eleven.h
    I need to split on
    _
    and put them in a directory structure.
    d
    2 replies · 2 participants
  • d

    Dariusz Kuc

    01/16/2020, 2:32 PM
    hello! I'm trying to publish my artifacts to sonatype (https://github.com/ExpediaGroup/graphql-kotlin/blob/master/build.gradle.kts#L107). It appears that my artifacts were uploaded to staging but never released. Is there a way to automatically release it? (i.e. same as using
    autoReleaseAfterClose
    property from
    nexus-staging-maven-plugin
    )?
    1 reply · 1 participant
  • s

    Shan

    01/19/2020, 4:05 AM
    This is what I see in my dependency tree, which is a bit confusing.. I can't use any of the classes from
    android-remote
    .
    f
    2 replies · 2 participants
  • p

    patrickdelconte

    01/19/2020, 12:09 PM
    how do I correctly configure a multiplatform gradle project tests? I would like to use junit5 on jvm. Currently I get this error `Execution failed for task ':jvmTest'.
    No tests found for given includes: [AmountTest.bla](filter.includeTestsMatching)
    In a normal jvm project this is fixed by adding
    test { userJUnitPlatform() }
    to the build script. However I am having a hard time figuring out how to do it in multiplatfom
    s
    5 replies · 2 participants
  • r

    Rodrigo Silva

    01/22/2020, 7:28 PM
    Hi all. I created a library, and added Kafka-client as dependency. I'm now importing this library into my project, but i cannot use Kafka-client methods. How can i accesses kafka-client methods without import twice (in my library and now in my project)
    c
    2 replies · 2 participants
  • r

    Ran Magen

    01/23/2020, 4:16 AM
    I'm getting started with converting all our modules build from groovy to kts. Learning this as I go. I'm trying to figure out something that I think should be simple? With groovy I could do this: //
    $rootDir/gradle/root.gradle
    ext.foo = "something"
    //
    $rootDir/gradle/root/git_util.gradle
    ext.complex_value = someValue.with {
      return doSomeHardWork(rootDir) + foo
    }
    //
    build.gradle
    apply {
      from "$rootDir/gradle/root/git_util.gradle"
    }
    
    def someMap = [
      key: complex_value
    ]
    I can't figure out how to get an equivalent going in Kotlin such that I could define `val`s that are globally available but are computed once and have access to the
    Project
    (e.g. using
    rootDir
    ) (I know I can make extension functions on
    Project
    in
    buildSrc
    but those are all functions that will get invoked on every call. Groovy has
    .memoize()
    but I don't think there's an equivalent in
    .kts
    )
    o
    1 reply · 2 participants
  • g

    genovich

    01/23/2020, 11:07 AM
    Hi, can anyone help me? I try to filter all
    com.android.build.gradle.tasks.AndroidJavaCompile
    . I add
    buildscript
    block like this
    buildscript {
        repositories {
            google()
            jcenter()
        }
    
        dependencies {
            classpath("com.android.tools.build:gradle:3.5.3")
        }
    }
    I invoke
    tasks.withType<AndroidJavaCompile>().all { println(name) }
    and there is no result. If I invoke
    tasks.matching { it.name == "compileDebugJavaWithJavac" }.all { println(javaClass) }
    , i’ve got
    com.android.build.gradle.tasks.AndroidJavaCompile_Decorated
    .
    m
    1 reply · 2 participants
  • m

    Marc Knaup

    01/24/2020, 9:06 AM
    Why is it that I’m always at war with Gradle 😭 Anybody got an idea?
    > Could not resolve org.junit.jupiter:junit-jupiter-api:5.0.0.
         Required by:
             project : > org.jetbrains.kotlin:kotlin-test-junit5:1.3.61
          > Cannot choose between the following variants of org.junit.jupiter:junit-jupiter-api:5.6.0:
              - javadocElements
              - sourcesElements
            All of them match the consumer attributes:
              - Variant 'javadocElements' capability org.junit.jupiter:junit-jupiter-api:5.6.0:
                  - Unmatched attributes:
                      - Found org.gradle.category 'documentation' but wasn't required.
                      - Found org.gradle.dependency.bundling 'external' but wasn't required.
                      - Found org.gradle.docstype 'javadoc' but wasn't required.
                      - Required org.gradle.jvm.version '7' but no value provided.
                      - Found org.gradle.status 'release' but wasn't required.
                      - Required org.jetbrains.kotlin.platform.type 'jvm' but no value provided.
                  - Compatible attribute:
                      - Required org.gradle.usage 'java-api' and found compatible value 'java-runtime'.
              - Variant 'sourcesElements' capability org.junit.jupiter:junit-jupiter-api:5.6.0:
                  - Unmatched attributes:
                      - Found org.gradle.category 'documentation' but wasn't required.
                      - Found org.gradle.dependency.bundling 'external' but wasn't required.
                      - Found org.gradle.docstype 'sources' but wasn't required.
                      - Required org.gradle.jvm.version '7' but no value provided.
                      - Found org.gradle.status 'release' but wasn't required.
                      - Required org.jetbrains.kotlin.platform.type 'jvm' but no value provided.
                  - Compatible attribute:
                      - Required org.gradle.usage 'java-api' and found compatible value 'java-runtime'.
    l
    2 replies · 2 participants
  • a

    arnaud.giuliani

    01/24/2020, 6:10 PM
    Hello all, I would like to write a Gradle plugin that access to developer's code. For example, If I write a class
    Foo
    in my Kotlin project and apply my plugin, I would like to get this compiled class
    Foo
    . Any hint regarding the topic?
    o
    m
    12 replies · 3 participants
Powered by Linen
Title
a

arnaud.giuliani

01/24/2020, 6:10 PM
Hello all, I would like to write a Gradle plugin that access to developer's code. For example, If I write a class
Foo
in my Kotlin project and apply my plugin, I would like to get this compiled class
Foo
. Any hint regarding the topic?
o

octylFractal

01/24/2020, 6:41 PM
it depends what you mean by "get", do you mean the source code, the compiled code for static analysis or transforms, or to actually load it into the classpath
a

arnaud.giuliani

01/24/2020, 8:01 PM
I think more about the compiled code
o

octylFractal

01/24/2020, 8:07 PM
assuming a standard setup where it is in the main sourceset, you can find it in
files(tasks.named("compileKotlin")).asFileTree
that FileTree contains files like
${projectRoot}/build/classes/kotlin/main/Foo.class
a

arnaud.giuliani

01/25/2020, 9:49 AM
ok, thanks for your answer
To precise more my case
because it's perhaps not completely that ...
It's for Koin framework. People are using an API to declare a module: https://start.insert-koin.io/#/quickstart/kotlin?id=declaring-dependencies
I would like to "get" this
Module
variable from Gradle to be able to check it
o

octylFractal

01/25/2020, 9:54 AM
that's going to be much more complicated. you need to load the class and probably the entire
runtimeClasspath
. I'm not very familiar with that myself so you'll have to ask someone else
a

arnaud.giuliani

01/25/2020, 1:57 PM
ok, thanks 👍
m

Michal Harakal

01/29/2020, 9:07 AM
Generally you can write something like anotation processor (you can have a look on https://github.com/Foso/MpApt or if you need a more power, compiler plugin can be also considered
View count: 3