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

    ubu

    02/27/2019, 6:46 PM
    Hi there. Is it possible to pass arguments to a Gradle task from command line?
    o
    • 2
    • 1
  • t

    Tasos Stamadianos

    02/28/2019, 1:04 AM
    hey everyone, I have a source control dependency for a Gradle project, but I can't seem to find a way to step through it in a client application. I'd really like to be able to step through my library so I can debug, but all I have is the ugly decompiled Java code. Is there a gradle setting either in my client application or the library which will package the source so that i can debug the library? thanks!
    👍 1
    x
    • 2
    • 4
  • d

    darkmoon_uk

    02/28/2019, 10:45 AM
    Where is the Kotlin Gradle plugin reference documentation? The tutorials here https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html are good, but they're only half the story. I can't find API docs...
    s
    • 2
    • 3
  • n

    Nikky

    03/01/2019, 6:58 PM
    can i exclude
    *.kts
    from files that gradle tries to compile ?
    e
    • 2
    • 3
  • t

    Tasos Stamadianos

    03/02/2019, 7:51 PM
    hi all, I have a library, let's call it
    Lib
    , which uses Jackson, and a client which uses
    Lib
    . If I try to make any calls in
    Lib
    which involve some Jackson calls under the hood, I get some exceptions related to Jackson not being able to load modules. The only way to fix this is to also include Jackson as a dependency in my client application, even tho it's already a dependency in
    Lib
    . Am I missing something here?
    e
    n
    • 3
    • 4
  • m

    Marc Knaup

    03/04/2019, 4:42 AM
    Is it just me or are
    kotlin-dsl
    1.2.4 and 1.2.5 broken?
    $ ./gradlew tasks --stacktrace
    
    > Configure project :
    WARNING: Unsupported Kotlin plugin version.
    The `embedded-kotlin` and `kotlin-dsl` plugins rely on features of Kotlin `1.3.20` that might work differently than in the requested version `1.3.21`.
    
    FAILURE: Build failed with an exception.
    …
    
    java.lang.NoClassDefFoundError: org/gradle/kotlin/dsl/provider/PrecompiledScriptPluginsSupport
            at org.gradle.kotlin.dsl.plugins.precompiled.PrecompiledScriptPlugins.apply(PrecompiledScriptPlugins.kt:77)
            at org.gradle.kotlin.dsl.plugins.precompiled.PrecompiledScriptPlugins.apply(PrecompiledScriptPlugins.kt:40)
    g
    j
    • 3
    • 7
  • a

    Alexander Mikhalchenko

    03/04/2019, 7:51 AM
    @Marc Knaup As I can see, the latest release on GitHub is v1.1.3. So 1.2.4 and 1.2.5 are probably still in development.
    m
    • 2
    • 1
  • l

    louiscad

    03/04/2019, 11:15 AM
    @Marc Knaup This in your `buildSrc`'s
    build.gradle.kts
    should fix your issue: https://github.com/LouisCAD/Splitties/blob/61a4035ba3b18270dbfb0828436b5045bff44919/buildSrc/build.gradle.kts#L32-L41
    m
    • 2
    • 1
  • g

    GarouDan

    03/04/2019, 8:09 PM
    Hi guys, my build is not passing on CIs integrations and it looks like it is because I was not able to translate propertly theses tasks to the
    build.gradle.kts
    format. Does someone knows how to do that?
    task jsinterop(type: Exec) {
        workingDir projectDir
        def ext = MPPTools.isWindows() ? '.bat' : ''
        def distributionPath = project.properties['org.jetbrains.kotlin.native.home'] as String
        if (distributionPath != null) {
            def jsinteropCommand = Paths.get(file(distributionPath).path, 'bin', "jsinterop$ext").toString()
    
            inputs.property('jsinteropCommand', jsinteropCommand)
            inputs.property('jsinteropPackageName', packageName)
            outputs.file(jsinteropKlibFileName)
    
            commandLine jsinteropCommand,
                    '-pkg', packageName,
                    '-o', jsinteropKlibFileName,
                    '-target', 'wasm32'
        } else {
            doFirst {
                // Abort build execution if the distribution path isn't specified.
                throw new GradleException("""\
                    |Kotlin/Native distribution path must be specified to build the JavaScript interop.
                    |Use 'org.jetbrains.kotlin.native.home' project property to specify it.
                """.stripMargin())
            }
        }
    }
    
    tasks.withType(KotlinNativeCompile).all {
        dependsOn jsinterop
    }
    Where I’m using this kotlin project as a basis: https://github.com/JetBrains/kotlin-native/blob/master/samples/html5Canvas/build.gradle
    • 1
    • 1
  • m

    mp

    03/05/2019, 6:08 PM
    When I have a non-empty
    module-info.java
    in a project (a simple Java project using the
    java-library
    plugin), IntelliJ gets super mad about basically everything in
    build.gradle.kts
    . Every element is red with
    Symbol is declared in unnamed module which is not read by this module
    . Is this expected, or is there some setting I can tweak?
    a
    • 2
    • 1
  • t

    thomasnield

    03/06/2019, 9:19 PM
    I get this unhelpful error saying "Plugin request for plugin already on the classpath must not include a version". If I remove the version number from the child project I get " Plugin [id: 'org.jetbrains.kotlin.jvm'] was not found in any of the following sources:" So how do I plugin Kotlin across multiple modules without that version number clashing?
    t
    n
    • 3
    • 6
  • t

    thomasnield

    03/06/2019, 9:26 PM
    @octylFractal thanks for the lead, are there any examples in the docs?
    o
    m
    • 3
    • 7
  • s

    sitepodmatt

    03/07/2019, 4:28 AM
    Completely ignoring android/mpp (as I understand there a bigger benefit here due to the complexitities of targetting such platform), doing server-side kotlin, what are people using gradle build scripts for in the real world when doing server/jvm work? I added dependencies (just like npm/package.json or pip/requirements.txt) but aside from that and a copy of a few lines from SO to produce a fat jar with main call I havent and honestly dont see a need to go beyond that (it was probably a sink of 20mins to convert to gradle.build.kts from groovy), anything else I need to do happens at a high level, Dockerfile for image build, cloudbuild.yaml for CI/CD flow, k8s for deployment target etc.. Enlighten my ignorant soul please
    g
    t
    d
    • 4
    • 8
  • a

    adalbert

    03/07/2019, 11:09 PM
    Hi! Have you used kotlin dsl with maven-publish? I am trying to get transitive dependencies like here https://gist.github.com/Robyer/a6578e60127418b380ca133a1291f017 in Kotlin DSL. I struggle with
    dep.transitive
    . The interface
    Dependency
    does not include anything with
    transitive
    . I am not sure how to port this groovy fragment to kotlin dsl
    j
    s
    • 3
    • 4
  • b

    bjartek

    03/14/2019, 7:27 AM
    how do i express this in gradle script kotlin
    compileTestGroovy.dependsOn compileTestKotlin
    compileTestGroovy.classpath += files(compileTestKotlin.destinationDir)
    testClasses.dependsOn compileTestGroovy
    g
    e
    • 3
    • 6
  • c

    cfleming

    03/18/2019, 1:53 AM
    I’m having a weird problem where the JVM used by my
    compileKotlin
    task seems to be different to the one used by Gradle itself. It’s somehow related to the version of the gradle-intellij-plugin I’m using to build an IntelliJ plugin - currently I use 0.3.10 of the plugin and everything in my build script should be set to use Java 8 to compile. However when I upgrade to 0.5.0-SNAPSHOT of the plugin because I need to test my plugin against the new Java 11 JBSDK, I start getting compile errors like:
    > Task :compileKotlin FAILED
    e: /Users/colin/dev/cursive/src/main/kotlin/cursive/debugger/Fragment.kt: (95, 25): Cannot access class 'com.sun.jdi.StringReference'. Check your module classpath for missing or conflicting dependencies
    indicating that my Kotlin code is being compiled with some 9+ JDK.
    d
    • 2
    • 2
  • c

    cfleming

    03/18/2019, 4:58 AM
    Actually, I see that this is more for the Gradle Kotlin DSL, I’ll ask over in #build-tools.
    g
    • 2
    • 3
  • j

    Justin

    03/18/2019, 5:20 AM
    Has anyone written a gradle plugin in Kotlin that leverages jetbrains code completion?
    g
    • 2
    • 13
  • j

    jakiej

    03/21/2019, 12:37 AM
    Hi there, how can a script plugin access a class that is defined in another plugin? eg.
    build.gradle.kts
    plugins {
    id("a")
    }
    
    apply(from = "b.gradle.kts")
    ---------------
    b.gradle.kts
    
    val c = A() //A is a class defined in plugin "a" and how do I make it accessible here?
    g
    d
    • 3
    • 15
  • w

    wakingrufus

    03/21/2019, 1:53 AM
    Should the gradle kotlin native plugin still be used for native only projects, or should everything be MPP?
    g
    r
    +2
    • 5
    • 19
  • m

    mp

    03/21/2019, 7:37 AM
    hello yesterday I`ve been playing with my build kts and found that this code
    val debugPort = "8000"
    enum class JreVersion( val value: String, val debugString: String = "", val additionalDependencies: DependencyHandlerScope.() -> Unit = {} ) {
        Eleven(value = "11.0.2-jre-slim",
            debugString = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:$debugPort",
            additionalDependencies = {
                implementation("org.glassfish.jaxb:jaxb-runtime")
            }
        )
    }
    won’t compile with
    Don't know how to generate outer expression: Class: class JreVersion
    I`m not sure should I report this as bug or not but seems that - something goes wrong because I`m expecting top level value defined before class to be accessible from class bellow
    a
    • 2
    • 1
  • e

    efemoney

    03/25/2019, 2:46 PM
    Why can we not define extension methods like this
    inline fun PluginDependenciesSpec.android(type: String = "application") = id("com.android.$type")
    to be used in the
    plugins
    block like
    plugins {
      android() // OR
      android("library")
    }
    h
    t
    • 3
    • 8
  • j

    jrod

    03/25/2019, 7:39 PM
    we have a gradle plugin that generates protos for both kotlin and java and i'm hitting an interesting bug where kotlin projects consume java protos. the compileKotlin task isn't able to find the java generated sources.
    val compileKotlinTask = project.tasks.named("compileKotlin") as TaskProvider<KotlinCompile>
            compileKotlinTask.configure {
              it.source(javaOutDirs)  // javaOutDirs is where the java protos are generated
              it.dependsOn(wireTask)
            }
    but my gradle output shows:
    14:56:58.695 [DEBUG] [org.gradle.api.Task] [KOTLIN] all kotlin sources: src/main/java/com/squareup/dinosaurs/Sample.kt
    14:56:58.695 [DEBUG] [org.gradle.api.Task] [KOTLIN] compileKotlin source roots: [
    	/...src/test/projects/kotlin-project-java-protos/src/main/java/com/squareup/dinosaurs/Sample.kt]
    14:56:58.695 [DEBUG] [org.gradle.api.Task] [KOTLIN] compileKotlin java source roots: [
    // why empty?!
    	]
    t
    • 2
    • 21
  • a

    aandreyev

    03/28/2019, 2:14 PM
    I am having issue with gradle kotlin DSL, seems to be IDEA-specific because ./gradlew run succeeds form command line but maybe someone here knows workaround. https://stackoverflow.com/questions/55399539/idea-reports-errors-for-shadowjar-task-in-build-gradle-kts-while-gradlew-run
    n
    • 2
    • 6
  • b

    Ben Madore

    03/28/2019, 8:28 PM
    plugins {
        id("java-library")
        kotlin("jvm") version "1.3.21"
        id("nebula.info-dependencies") version ("5.0.0")
        id("org.owasp.dependencycheck") version ("4.0.2")
        id("com.gorylenko.gradle-git-properties") version ("2.0.0")
        id("io.freefair.lombok") version ("3.2.0")
    }
    
    configure<JavaPluginConvention> { // config built-in works fine
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
    
    configure<GitPropertiesPluginExtension> { // FAIL Unresolved reference: GitPropertiesPluginExtension
       dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" 
        dateFormatTimeZone = "UTC"
    }
    m
    • 2
    • 4
  • s

    Shan

    03/29/2019, 9:33 AM
    Anyone know why I get this compile error when trying to add the Kotlin jvm plugin to a subproject this way?
    Cannot resolve external dependency org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.20 because no repositories are defined.
    Required by: 
          project :
    Untitled.pl
    r
    c
    • 3
    • 19
  • s

    Shan

    03/29/2019, 9:38 AM
    Using Gradle 5.3.1, Kotlin version 1.3.21
    r
    • 2
    • 2
  • b

    Ben Madore

    03/29/2019, 1:58 PM
    how do folks feel about this approach: https://handstandsam.com/2018/02/11/kotlin-buildsrc-for-better-gradle-dependency-management/ i’ve always ensured that there is only a single version of all my dependencies (generally using the
    io.spring.dependency-management
    plugin in the root project) and versions stored in
    gradle.properties
    c
    r
    • 3
    • 30
  • s

    Smallville7123

    03/30/2019, 12:42 AM
    and it seems like i will need to repeat the steps every single time i want to test a small change to my plugin
    d
    w
    g
    • 4
    • 4
  • i

    igor.wojda

    03/30/2019, 1:38 PM
    Hey I am trying to define single task that can run all static checks (ktlint, android lint, detekt) and tests - single taks that could verify project correctness. As far as I know only way to do it in gradle is to define task that depends on other tasks so they will run before:
    task("prCheck") {
        afterEvaluate {
            // Non-android modules do not have lint task
            val lintDependencies = subprojects.mapNotNull { "${it.name}:lint" }
    
            val taskDependencies = mutableListOf<String>("ktlintCheck", "detekt", "testDebugUnitTest")
            taskDependencies.addAll(lintDependencies)
            dependsOn(taskDependencies)
        }
    }
    Above task works well for android lint, detekt, ktlint, however it fails to resolve
    testDebugUnitTest
    task 🤔
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Could not determine the dependencies of task ':prCheck'.
    > Task with path 'testDebugUnitTest' not found in root project 'android'.
    g
    • 2
    • 7
Powered by Linen
Title
i

igor.wojda

03/30/2019, 1:38 PM
Hey I am trying to define single task that can run all static checks (ktlint, android lint, detekt) and tests - single taks that could verify project correctness. As far as I know only way to do it in gradle is to define task that depends on other tasks so they will run before:
task("prCheck") {
    afterEvaluate {
        // Non-android modules do not have lint task
        val lintDependencies = subprojects.mapNotNull { "${it.name}:lint" }

        val taskDependencies = mutableListOf<String>("ktlintCheck", "detekt", "testDebugUnitTest")
        taskDependencies.addAll(lintDependencies)
        dependsOn(taskDependencies)
    }
}
Above task works well for android lint, detekt, ktlint, however it fails to resolve
testDebugUnitTest
task 🤔
FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':prCheck'.
> Task with path 'testDebugUnitTest' not found in root project 'android'.
g

gildor

03/30/2019, 3:02 PM
Where do you create this task? It will work only in module with this task
Also, it may be somehow related to task creation
i

igor.wojda

03/30/2019, 6:48 PM
I am defining
prCheck
task in project root level
build.gradle.kts
, so and I am able to run it in project root like this
./gradlew prCheck
- the only problem is
testDebugUnitTest
task that comes from Android FYI I can run
./gradlew testDebugUnitTest
without any problems - the problem starts when I want to use it as dependency
g

gildor

03/31/2019, 12:58 AM
No, it will not work like that, you cannot just define task and depend on task in another module
Dependencies by default only resolve tasks in the same module
Instead, apply this task in app your modules
You can run it like ./gradlew testDebugUnitTest only because Gradle resolve tasks from all modules and run all of them (with the same name), but this doesn't work in task dependencies, so to implement such check task: 1. Apply it to every module, so it will resolve dependencies and Gradle will.run check task on every module where this task exists 2. You probably can get task from submodule directly, like
submodules["myModule"].tasks["testDebugUnitTest]
and set dependency on it, but didn't try this approach, and all default Gradle task work like 1, not like 2
View count: 7