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

    Tucker Barbour

    10/20/2020, 10:25 AM
    Is it possible to prevent code from importing packages from transitive dependencies pulled from maven central? I know you can do that from other gradle projects via 'implementation' and 'api' Something similar to Bazel's 'strict visibility'?
    m
    • 2
    • 4
  • t

    Tucker Barbour

    10/20/2020, 1:30 PM
    I’m trying to figure out how to publish the “fat jar” created by the shadow plugin, via the
    shadowJar
    task using the gradle kotlin dsl. So far I’ve had no success after reading through the shadow and maven-publish documentation. Has anyone solved this issue?
    b
    • 2
    • 12
  • b

    bitkid

    10/20/2020, 5:06 PM
    i have a more general project layout question: i have a gradle project with submodules ... commons, test-commons and app ... test-commons has only external dependencies, commons depends on test-commons .. and app has the dependency commons and the test dependency test-commons. now in my test-commons i use for example the library wiremock, so i added implementation("com.github.tomakehurst:wiremock-jre8:2.27.2"). if i want to have wiremock also in commons as test dependency there are 2 ways to do that. instead of implementation("wiremock") in test-commons i could use api("wiremock") which exposes wiremock to all projects which depend on test-commons. the other way would be to use testImplementation("wiremock") in my test.kotlin-common-conventions.gradle.kts and just use the same version. but that feels somehow not clean (because i would have to reuse the version somehow). any ideas on that?
    t
    • 2
    • 4
  • w

    wakingrufus

    10/23/2020, 10:12 PM
    Has anyone out there used buildSrc or a custom distributions to enhance the gradle DSL via extension functions? I am thinking like this
    fun PluginDependenciesSpecScope.libraryPlugins(){
        id("java-library")
        id("io.freefair.lombok")
    }
    which could then be called in a project like
    plugins {
        libraryPlugins()
    }
    or better yet, an extension method that could be invoked at the root in the project script that could add plugins and dependencies all at once? For some reason, I just get unresolved references, even though my IDE thinks it is fine
    m
    g
    • 3
    • 12
  • k

    kenkyee

    10/25/2020, 11:47 PM
    Trying to create a gradle plugin in the buildsrc directory and get this cryptic error even though my build.gradle.kts and plugin definitions seem ok: Cannot access 'java.lang.Object' which is a supertype of ConfigPlugin. Check your module classpath for missing or conflicting dependencies and there are bunch of warnings about Kotlin stdlib conflicts between 1.3.72 and 1.4.10. Kotlin 1.4 includes its own stdlib so I don't see why it's complaining about these conflicts? Gradle is version 6.7
    t
    m
    • 3
    • 6
  • n

    nikunjsakhrelia

    10/27/2020, 10:26 AM
    Hi, I am trying
    versionCode = majorVersion * 10000 + minorVersion * 100 + patchVersion
    in build.gradle.kts
    b
    n
    • 3
    • 10
  • g

    Gabriel

    10/29/2020, 9:14 AM
    Hi folks, I'm using kotlin dsl in my gradle scripts for android project, but as is showing me
    Expression 'android' cannot be invoked as a function. The function 'invoke()' is not found
    a brief view of my gradle file is this:
    plugins {
    	id("com.android.application")
    	kotlin("android")
    }
    
    android {
    	compileSdkVersion(TARGET_SDK_VERSION)
    
    	defaultConfig {
    		minSdkVersion(MIN_SDK_VERSION)
    		targetSdkVersion(TARGET_SDK_VERSION)
    
    		testInstrumentationRunner("androidx.test.runner.AndroidJUnitRunner")
    		consumerProguardFiles("<http://consumer-rules.pro|consumer-rules.pro>")
    	}
    
    	buildTypes {
    		getByName("release") {
    			isMinifyEnabled = false
    			proguardFiles(
    				getDefaultProguardFile("proguard-android-optimize.txt"),
    				"<http://proguard-rules.pro|proguard-rules.pro>"
    			)
    		}
    	}
    
    	compileOptions {
    		sourceCompatibility = JavaVersion.VERSION_1_8
    		targetCompatibility = JavaVersion.VERSION_1_8
    	}
    
    	kotlinOptions {
    		jvmTarget = "1.8"
    		useIR = true
    	}
    
    	buildFeatures {
    		compose = true
    	}
    	composeOptions {
    		kotlinCompilerExtensionVersion = COMPOSE_VERSION
    		kotlinCompilerVersion = KOTLIN_VERSION
    	}
    }
    v
    n
    j
    • 4
    • 5
  • r

    Roman Konstantynovskyi

    10/29/2020, 1:54 PM
    Hello. I've a question about exposing dependencies in libs builded with gradle. In my spring boot application (A) I'm using my own starter (S1), which use another starter(S2), which use a library (L).
    A -> S1 -> S2 -> L
    In my starter (S1) I can use all classes from the library (L). But if I add my starter (S1) as a dependency to my application (A) then I can't use classes from the library and from the second starter (S2), because they aren't in
    compileClasspath
    . In my starter (S1) I'm adding second starter as
    implementation
    . And also I use this configuration for adding my starter to application. I've read that to expose dependency I should use ``java-library`` plugin for gradle and use
    api
    configuration in my starter (S1), but this didn't help me 😞 And if I add S2 to my S1 using deprecated
    compile
    configuration all works well. 🤔 build.gradle.kts (starter S1)
    plugins {
    	// other plugins
    	`java-library`
    }
    
    dependencies {
        // other dependencies
    	api("some:starter:1.0.0") // starter S2
    }
    build.gradle.kts (application A)
    dependencies {
        // other dependencies
    	implementation("own:starter:1.0.0") // starter S1
    }
    s
    v
    • 3
    • 4
  • e

    eekboom

    10/29/2020, 4:31 PM
    I am trying to convert a gradle build from groovy to Kotlin but I am stumped here - groovy version:
    gradle.ext.token = "foo"
    This is in settings.gradle, so rootProject is not available. (I think?!) In Kotlin "gradle" is also available in settings.xml, but it seems it does not implement "ExtensionAware", so the "extra" properties do not seem to work here.
    val token: String by gradle.extra("foo")
    => Unresolved reference (on "extra")
    v
    • 2
    • 7
  • p

    PHondogo

    10/29/2020, 8:49 PM
    Hello! Is it possible to create several common targets in MPP? If yes then how?
    b
    • 2
    • 8
  • k

    kenkyee

    10/31/2020, 10:20 PM
    Trying to convert this into a buildSrc plugin and can't figure out the right syntax for this..googling for this is not useful as you can imagine 😂 You can get to kotlinOptions by doing this:
    tasks.withType(KotlinCompile::class.java).configureEach {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }
    But there's no KaptCompile?
    Untitled
    v
    • 2
    • 2
  • b

    bodo

    11/02/2020, 9:57 AM
    Is it possible to add imports in a custom gradle plugin automatically to the build.gradle.kts file, e.g
    class MyPlugin : Plugin<Project> {
       fun apply(project: Project) {
          project.addImport("import com.foo.Foo") // i need the command for this
       }
    }
    so when i use it build.gradle i can directly access it
    import com.foo.Foo   // i want to get rid of this import
    
    plugins {
       id("MyPlugin")
    }
    
    dependencies {
       // use Foo here directly without the need to add the import on top of every build.gradle.kts file when adding the "MyPlugin" plugin
    }
    k
    n
    • 3
    • 6
  • b

    bodo

    11/03/2020, 3:13 PM
    another question. at the moment i want to write custom gradle plugins with the help of includedBuild. so i created a directory and marked it as includedBuild in settings.gradle.ktx. • in android studio 4.1 it is working and shows no errors • in android studio 4.2.0-alpha15 it is also working (building the project) but every gradle.ktx file is now showing errors. is this a know bug?
    v
    • 2
    • 5
  • m

    Mitchell Syer

    11/06/2020, 4:00 AM
    I have a question, I have a gradle plugin I made that generates code using KotlinPoet, and it puts the code file in build/generated/bot-compiler-plugin/Code/Commands, but its not being registered as a sources root, like SQL Delight does, and I am not sure how to make it do that I am using Gradle 6.5.1 with kts gradle.build files, and am using the MyApt library for annotation preprocessing to generate the kotlin code
    v
    j
    m
    • 4
    • 7
  • a

    andylamax

    11/06/2020, 9:39 AM
    Hi there. I am trying to deploy gradle plugins to maven central. For them to be accepted in maven-central, I need to them to be signed. All of this how ever is going to be done in a CI & CD server. The signing needs a keyId, a password, and a file. A bit not suitable for CI. Are there best options? Those of you who have done this before, can you provide with me a helping hand? Probably point me to a
    build.gradle.script
    ?
    m
    v
    • 3
    • 15
  • c

    christophsturm

    11/06/2020, 4:12 PM
    i have this file in my buildSrc project:
    package r2dbcfun
    
    object ProjectConfig {
        const val eap = false
        val kotlinVersion = if (eap) "1.4.20-RC" else "1.4.10"
    }
    in my normal build file i have an import for it:
    import r2dbcfun.ProjectConfig
    still in the plugins block i have to specify the whole package:
    kotlin("jvm").version(r2dbcfun.ProjectConfig.kotlinVersion)
    probably because the plugins block is treated separately from the build file. idea shows the package as grayed out and wants to remove it, which results in an invalid build file
    j
    • 2
    • 3
  • h

    Hossain

    11/07/2020, 12:11 AM
    I will start with the official repo content, which is not very old. Thanks
    v
    • 2
    • 1
  • a

    andylamax

    11/07/2020, 12:48 AM
    how long does it take gradle to approve plugins? its almost 12 hrs now, and still my plugins are pending
    v
    b
    +2
    • 5
    • 13
  • g

    Gabriel

    11/07/2020, 9:39 PM
    Does anyone else get this when trying to do kotlin dsl for android build.gradle files? Everything compiles and runs, it's just looks like android studio having a mood
    "Cannot access 'java.lang.Comparable' which is a supertype of 'org.gradle.kotlin.dsl.KotlinBuildScript'. Check your module classpath for missing or conflicting dependencies"
    b
    w
    • 3
    • 2
  • f

    fmd

    11/09/2020, 4:01 PM
    Does the
    kotlin
    plugin automatically add dependencies to the Kotlin standard library when adding the plugin to a Java project? I just had the case, where our Android build's custom linter rules module leaked the standard library (as public module dependency), since the
    kotlin-stdlib
    dependency implicitly came from "somewhere". Explicitly stating the standard library as
    compileOnly
    dependency, configured Gradle to filter it away from the API/metadata configurations, and stopped leaking it.
    :yes: 2
    v
    • 2
    • 7
  • j

    Joao Birk

    11/10/2020, 6:28 PM
    Hi there, QQ:
    build.gradle
    using
    plugin id 'com.android.dynamic-feature'
    and `plugin id `kotlin-android``Im able to set :
    buildFeatures.dataBinding = true
    converting it to Kotlin DSL
    build.gradle.kts
    and using
    buildFeatures.dataBinding = true
    says
    dataBinding
    is non existent, I only see
    viewBinding
    : https://developer.android.com/reference/tools/gradle-api/4.1/com/android/build/api/dsl/BuildFeatures Does that mean I still need to use the deprecated way (
    dataBinding.isEnabled = true
    ) on DSL?
    WARNING: DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'.
    y
    • 2
    • 1
  • b

    basher

    11/11/2020, 12:23 AM
    in this PR i’m trying to make task inputs in a plugin that can be set in a build.gradle file, but for some reason I get a runtime error saying those properties don’t exist: https://github.com/cashapp/sqldelight/pull/2082#discussion_r520255932. tried a bunch of things to try to expose them. is this not possible? feel like i’m just missing something small
    v
    • 2
    • 3
  • n

    napperley

    11/15/2020, 11:51 PM
    Is it possible to apply the maven-publish plugin in a custom build file? Seems as though there are no errors when applying the plugin, however the functionality that the plugin provides (eg publishing block) isn't being made available.
    g
    m
    v
    • 4
    • 43
  • n

    Naoki Hidaka

    11/19/2020, 8:17 AM
    Is there a problem with JCenter?
    v
    m
    • 3
    • 5
  • b

    Brady Aiello

    11/19/2020, 7:03 PM
    Haven’t had this problem before, but I can’t build an Android project at all, from terminal or Android Studio. It just hangs forever, and --info isn’t particularly helpful. I’m using Kotlin 1.4.10, Kotlin Gradle DSL, Android Studio 4.2 Canary 16. Still on Catalina. Anyone have this problem?
    v
    • 2
    • 2
  • t

    tieskedh

    11/19/2020, 8:45 PM
    I've an question. I have a gradle-plugin that generates some code. However, Kotlin doesn't seem to find the code during compilation... I'm using Multiplatform, is there something I'm missing?
    class PropsToObjectPlugin : Plugin<Project> {
        override fun apply(target: Project) {
            val extension: PropsToObjectExtension = target
                .extensions
                .create("propsToObject")
    
            val buildDir = target.file(
                "${target.buildDir}/generated/source/props"
            )
    
            val taskProvider = target.tasks
                .register<PropertyObjectGeneratingTask>(
                    "generatePropertyObject"
                ) {
                    fileName = target.file(extension.propFileName)
                    this.genDir = buildDir
                }
    
            target.tasks.withType<KotlinCompile> {
                //<https://youtrack.jetbrains.com/issue/KT-42241>
                val srcTask = this as SourceTask
                srcTask.dependsOn(taskProvider)
                val srcSet = target
                    .objects
                    .sourceDirectorySet("nl.devhaan.props", "generatedPropertyObject")
                    .srcDir(buildDir)
                srcTask.source(srcSet)
            }
        }
    }
    b
    • 2
    • 2
  • a

    almibe

    11/20/2020, 3:26 AM
    I've been out of the kotlin/gradle loop for a minute but when did
    gradle init
    start creating a
    lib
    subdirectory to put
    src
    in when you create a library instead of just putting
    src
    in the current project directory? Did they just start doing that in 6.7? That seems really obnoxious to me. Is there a reason for this?
    n
    b
    v
    • 4
    • 13
  • p

    Pacane

    11/20/2020, 4:00 PM
    Is there a way to add an "implementation" dependency to
    gradle-kotlin-dsl-extensions-6.7.jar
    to a plugin project? I'm trying to access some extension functions in there like
    fun DependencyHandler.`implementation`(dependencyNotation: Any): Dependency? =
        add("implementation", dependencyNotation)
    m
    v
    g
    • 4
    • 35
  • b

    bjonnh

    11/20/2020, 8:18 PM
    anytime I add a implementation(project (":mycpplib")) I get a No variant found. And I'm struggling to find examples of people doing kotlin and JNI where everything is built with gradle
    b
    n
    g
    • 4
    • 22
  • m

    Mohamed Daif

    11/21/2020, 2:30 PM
    I am learning Kotlin by hyperskill.org JetBrain Academy I getting this error when checking my solution but when running it in IDE it's working fine https://hyperskill.org/projects/83/stages/458/implement is this issue can be fixed by me or only by hyperskill JetBrain Academy The compile configuration has been deprecated for dependency declaration. This will fail with an error in Gradle 7.0. Please use the implementation configuration instead. Consult the upgrading guide for further information: https://docs.gradle.org/6.6.1/userguide/upgrading_version_5.html#dependencies_should_no_longer_be_declared_using_the_compile_and_runtime_configurations         at build_bzr9s6nt7rztzjinzwhqs1atm$_run_closure1$_closure4.doCall(/mnt/sdb1/IntelliJIDEAProjects/Flashcards/build.gradle:23)         (Run with --stacktrace to get the full stack trace of this deprecation warning.)
    v
    • 2
    • 2
Powered by Linen
Title
m

Mohamed Daif

11/21/2020, 2:30 PM
I am learning Kotlin by hyperskill.org JetBrain Academy I getting this error when checking my solution but when running it in IDE it's working fine https://hyperskill.org/projects/83/stages/458/implement is this issue can be fixed by me or only by hyperskill JetBrain Academy The compile configuration has been deprecated for dependency declaration. This will fail with an error in Gradle 7.0. Please use the implementation configuration instead. Consult the upgrading guide for further information: https://docs.gradle.org/6.6.1/userguide/upgrading_version_5.html#dependencies_should_no_longer_be_declared_using_the_compile_and_runtime_configurations         at build_bzr9s6nt7rztzjinzwhqs1atm$_run_closure1$_closure4.doCall(/mnt/sdb1/IntelliJIDEAProjects/Flashcards/build.gradle:23)         (Run with --stacktrace to get the full stack trace of this deprecation warning.)
v

Vampire

11/21/2020, 4:37 PM
In what form do you submit a solution there?
m

Mohamed Daif

11/22/2020, 6:00 PM
submit by EduTool the issue was in java test file import .../IntelliJIDEAProjects/Flashcards/Flashcards/task/test/FlashcardsTest.java
import flashcards.Main;
instead of
import flashcards.MainKt;
every time after submit must be edit it again
View count: 6