https://gradle.com/ logo
Join Slack
Powered by
# kotlin-dsl
  • g

    gold man

    06/23/2024, 8:53 PM
    I have an issue as follow\
    🧵 1
  • g

    gold man

    06/23/2024, 8:53 PM
    Plugin [id: 'com.android.application', version: '8.5.0', apply: false] was not found in any of the following sources: * Try:
    Run with --info or --debug option to get more log output.
    Run with --scan to get full insights.
    Get more help at https://help.gradle.org.
    🧵 1
  • g

    gold man

    06/23/2024, 8:54 PM
    this is build error in Android Studio
    🧵 1
  • g

    gold man

    06/23/2024, 8:54 PM
    Who can help me?
    🧵 1
    v
    • 2
    • 2
  • f

    Fredrick Eisele

    07/15/2024, 8:37 PM
    I am looking for a modern custom plugin example which uses Kotlin for the plugin and the *.gradle.kts files. I found https://github.com/gradle/kotlin-dsl-samples/blob/master/samples/README.md Those are a few years old. Are they still current? In particular I am looking at something like: • https://github.com/gradle/kotlin-dsl-samples/tree/master/samples/testkit • https://github.com/gradle/kotlin-dsl-samples/blob/master/samples/gradle-plugin • https://github.com/gradle/kotlin-dsl-samples/tree/master/samples/precompiled-script-plugin
    c
    • 2
    • 6
  • r

    Radosław Panuszewski

    08/17/2024, 6:01 PM
    Hey guys! I'm a big fan of Kotlin DSL and its typesafe accessors in particular 😉 Although, one of the documentation examples got me thinking recently:
    Copy code
    plugins {
        application                                     // by name
        java                                            // by name
        id("java")                                      // by id - recommended
        id("org.jetbrains.kotlin.jvm") version "1.9.0"  // by id - recommended
    }
    Why is the non-typesafe plugin application
    id("java")
    recommended over the typesafe accessor
    java
    ? For me, the typesafe one is both easier to read and easier to write (thanks to IDE autocompletion) + there is no way to make a typo. I tend to use typesafe accessors wherever possible in my buildscripts and I don't see any reason to prefer the non-typesafe plugin application 🤔
    p
    l
    v
    • 4
    • 31
  • s

    Srikanta Subudhi

    08/23/2024, 3:25 AM
    during implementation enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") it shows error org.gradle.api.internal.catalog.GeneratedClassCompilationException: Unable to compile generated sources: - File RootProjectAccessor.java, line: 44, method getRun() is already defined in class org.gradle.accessors.dm.RootProjectAccessor
    Unable to compile generated sources:
    - File RootProjectAccessor.java, line: 44, method getRun() is already defined in class org.gradle.accessors.dm.RootProjectAccessor
    v
    • 2
    • 1
  • c

    CAB

    08/30/2024, 4:01 PM
    I am trying to upgrade my build to use latest versions of Gradle and plugings. I switched from 7.2 (other projects from even earlier versions) to 8.5. Now I got the problem in the "plugins" section: it doesn't like "maven" plugin and expect it to be a function. This seems because the "maven" need to be configured to the specific repository. I need to use the mavenCentral and people on different resources suggesting to use "mavenCentral()", but my build.gradle.kts doesn't recognize this function at all. It complains:
    Copy code
    Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
    public inline fun RepositoryHandler.mavenCentral(vararg args: Pair<String, Any?>): MavenArtifactRepository defined in org.gradle.kotlin.dsl
    👏 1
    t
    v
    • 3
    • 7
  • s

    Srikanta Subudhi

    09/10/2024, 12:03 AM
    Hi everyone can you please help me on this issue kotlinOptions(KotlinJvmOptionsDeprecated /* = KotlinJvmOptions */.() -> Unit): Unit' is deprecated. Please migrate to the compilerOptions DSL. I have tried the url but nothing work
    v
    • 2
    • 4
  • m

    Martin

    09/10/2024, 1:57 PM
    How to I clear my
    build.gradle.kts
    compilation cache?
    v
    • 2
    • 2
  • s

    Srikanta Subudhi

    09/12/2024, 7:11 PM
    Hi everyone can anyone help me to solve the issue The Compose Compiler requires the Compose Runtime to be on the class path, but none could be found. The compose compiler plugin you are using (version 1.5.12) expects a minimum runtime version of 1.0.0.
    v
    • 2
    • 1
  • d

    Dheeraj Gupta

    09/28/2024, 3:35 PM
    this submodule name is test with build.kts file contains
    Copy code
    configurations.create("default")
    artifacts {
      add("default", files("1st.aar"))
      add("default", file("2nd.aar"))
    }
    trying to add this 2 .aar files in submodules then this submodule is added in another core module like this
    Copy code
    implementation(project(":test"))
    but the only 1.aar files can be inflated in the core module why the other '2.arr' file data is not coming in that core module can anyone help here.
    v
    • 2
    • 5
  • t

    Tomáš Procházka

    10/21/2024, 12:22 PM
    The new
    Copy code
    TYPESAFE_PROJECT_ACCESSORS
    has one strange thing. It generate type safe accessor also for root project folder, why? When you then try to run such project on TeamCity it fails with
    Copy code
    org.gradle.api.InvalidUserDataException: Cannot generate project dependency accessors:
      - Cannot generate project dependency accessors because project '55cb9b3dea7c8b39' doesn't follow the naming convention: [a-zA-Z]([A-Za-z0-9\-_])*
    Watched directory hierarchies: [/Users/teamcity/buildAgent/work/55cb9b3dea7c8b39]
    Because root project folder is 55cb9b3dea7c8b39 in this case. For me doesn't make sense to make project dependent on the folder name where project was checkouted. It can be anything.
    m
    a
    • 3
    • 18
  • k

    Kelvin Chung

    10/24/2024, 6:27 PM
    Quick question on Kotlin language: is there a reason why
    Copy code
    val foobar by if (flag) {
        tasks.registering(Foo::class)
    } else {
        tasks.registering(Bar::class)
    }
    fails to compile?
    e
    v
    • 3
    • 5
  • s

    StefMa

    11/20/2024, 7:20 PM
    Hi guys, I just read the article about Kotlin Scripting in the JetBrains blog. Given that JetBrains also invest heavily in Amper I ask myself if this might be problem or concern for Gradle, now or in the future?! This is the blog: https://blog.jetbrains.com/kotlin/2024/11/state-of-kotlin-scripting-2024/
    e
    t
    • 3
    • 7
  • h

    Hantsy Bai

    11/28/2024, 3:46 AM
    Today I tried to upgrade to Kotlin 2.1.0 in my Gradle project • Java 21 • Gradle 8.11.1 with
    --debug
    prarameter when building the project, and got the following build error>
    Copy code
    11-28T11:39:13.093+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
    2024-11-28T11:39:13.093+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
    2024-11-28T11:39:13.094+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
    2024-11-28T11:39:13.094+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
    2024-11-28T11:39:13.094+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':compileKotlin'.
    2024-11-28T11:39:13.094+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > 'void org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments.setExtraWarnings(boolean)'
    e
    t
    u
    • 4
    • 18
  • h

    Hantsy Bai

    11/28/2024, 4:38 AM
    use
    --scan
    and got the details like this.
    Copy code
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileKotlin'.	
    	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:130)	
    		•••
    Caused by: java.lang.NoSuchMethodError: 'void org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments.setExtraWarnings(boolean)'	
    	at org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerToolOptionsHelper.fillCompilerArguments$kotlin_gradle_plugin_common(KotlinCommonCompilerToolOptionsHelper.kt:15)	
    	at org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptionsHelper.fillCompilerArguments$kotlin_gradle_plugin_common(KotlinCommonCompilerOptionsHelper.kt:14)	
    	at org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsHelper.fillCompilerArguments$kotlin_gradle_plugin_common(KotlinJvmCompilerOptionsHelper.kt:14)	
    	at org.jetbrains.kotlin.gradle.tasks.KotlinCompile$createCompilerArguments$1$1.invoke(KotlinCompile.kt:239)	
    	at org.jetbrains.kotlin.gradle.tasks.KotlinCompile$createCompilerArguments$1$1.invoke(KotlinCompile.kt:220)	
    	at org.jetbrains.kotlin.gradle.plugin.CreateCompilerArgumentsContextImpl$ContributeCompilerArgumentsContextImpl.primitive(KotlinCompilerArgumentsProducer.kt:130)	
    	at org.jetbrains.kotlin.gradle.tasks.KotlinCompile$createCompilerArguments$1.invoke(KotlinCompile.kt:220)	
    	at org.jetbrains.kotlin.gradle.tasks.KotlinCompile$createCompilerArguments$1.invoke(KotlinCompile.kt:219)	
    	at org.jetbrains.kotlin.gradle.plugin.CreateCompilerArgumentsContextImpl.create(KotlinCompilerArgumentsProducer.kt:77)	
    	at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.createCompilerArguments(KotlinCompile.kt:526)	
    	at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.createCompilerArguments(KotlinCompile.kt:55)	
    	at org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer$DefaultImpls.createCompilerArguments$default(KotlinCompilerArgumentsProducer.kt:54)	
    	at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.executeImpl(AbstractKotlinCompile.kt:305)	
    	at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute(AbstractKotlinCompile.kt:259)	
    		•••
  • b

    Blake Oliveira

    12/08/2024, 5:02 PM
    I’m near the end of creating a KMP gradle convention plugin and ran into some issues that I think may be because I’m configuring things too late (generated sources aren’t being picked up). Android Gradle Plugin has a hook that makes it easy to configure at the right time. Is there something similar to the AGP version but for KMP? Android has the
    finalizeDsl
    hook.
    Copy code
    plugins.withId("com.android.application") {
       val androidComponents = extensions.getByType(ApplicationAndroidComponentsExtension::class.java)
       androidComponents.finalizeDsl {
         it.configureAndroid(extension)
       }
     }
    v
    • 2
    • 4
  • k

    Kevin Loveland

    12/21/2024, 1:19 AM
    Is there a way to declare a task to list all of the dependencies for a the
    runtimeClasspath
    configuration? I’m trying to find a transitive dependency that is causing a problem and generating a flat list of dependency would be a great help. With the help of Google, I can find outdated/Groovy ways of declaring a task, but none of these solutions seem to work.
    s
    v
    • 3
    • 10
  • m

    Mudasar Cheema

    01/06/2025, 12:22 PM
    Hi! In my
    build.gradle.kts
    i have a task for copy file from the project into
    .git/hooks
    folder, but it wont work? Can anyone explain me what i am doing wrong here?
    Copy code
    tasks {
    
        withType<KotlinCompile>().configureEach {
            dependsOn("ktlintFormat")
        }
    
        withType<ShadowJar>().configureEach {
            enabled = true
            archiveFileName.set("app.jar")
            manifest {
                attributes["Main-Class"] = "no.nav.sokos.prosjektnavn.ApplicationKt"
            }
            finalizedBy(koverHtmlReport)
        }
    
        ("jar") {
            enabled = false
        }
    
        withType<Test>().configureEach {
            useJUnitPlatform()
    
            testLogging {
                showExceptions = true
                showStackTraces = true
                exceptionFormat = FULL
                events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
            }
    
            reports.forEach { report -> report.required.value(false) }
        }
    
        withType<Wrapper> {
            gradleVersion = "8.11"
        }
    
        withType<Copy> {
            val preCommitHook = file("./.git/hooks/pre-commit")
            if (!preCommitHook.exists()) {
                println("⚈ ⚈ ⚈ Running Add Pre Commit Git Hook Script on Build ⚈ ⚈ ⚈")
                from(file("./.scripts/pre-commit"))
                into(file("./.git/hooks"))
                println("✅ Added Pre Commit Git Hook Script.")
            }
        }
    }
    v
    s
    • 3
    • 7
  • k

    Kelvin Chung

    01/16/2025, 8:47 AM
    Question: In Gradle 8.10, apparently this doesn't compile:
    Copy code
    val foo by if (condition) {
      tasks.registering
    } else {
      tasks.registering(Foo::class)
    }
    and I would need to do this instead:
    Copy code
    val foo by if (condition) {
      tasks.registering(DefaultTask::class)
    } else {
      tasks.registering(Foo::class)
    }
    Is this a thing in newer versions of Gradle?
    e
    v
    • 3
    • 2
  • s

    Suresh

    01/18/2025, 9:36 PM
    Hi, What’s the best way to publish a Gradle pre-compiled script plugins to Maven Central that uses a version catalog? Let me explain the project structure in more detail. • I have a plugin project that contains many Gradle pre-compiled script plugins. The plugin uses Gradle version catalog entries for adding dependencies or applying plugins. Currently, I’m using a hack to expose the version catalog in pre-compiled script plugins (
    implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
    ). Everything is building fine, and I can publish the plugin JAR artifact to Maven Central (I’m not using Gradle plugin marker artifacts). • Now, I want to consume the plugin in another project. The project will use a settings plugin (from the published plugin project) and the same version catalog file. Here’s the first issue I’m encountering:
    Copy code
    > Could not create an instance of type org.gradle.accessors.dm.LibrariesForLibs.
    > Could not generate a decorated class for type LibrariesForLibs.
    > org/gradle/api/internal/attributes/ImmutableAttributesFactory
    I could fix this by adding the generated catalog version classes to the plugin jar artifact. However, this introduces a new issue: when the plugin is used in the consumer project, it conflicts with the version catalog classes generated there. Additionally, new entries added to the consumer’s version catalog are not showing up. Is there any suggestion or tip on how to properly use a version catalog in this scenario, or am I complicating things here? Thanks!
    v
    p
    • 3
    • 19
  • t

    Thomas Keller

    01/20/2025, 2:28 PM
    Hi all, I was astounded to see that the publication of my very small build convention plugin created a JAR file of more than one megabyte of size. After unzipping the JAR and looking into its contents I saw hundreds and hundreds of small auto-generated files underneath
    gradle/kotlin/dsl/accessors
    , in total more than 900 files totalling about 4,2 MB uncompressed. Because I want to keep my upload / consumption times low I wonder if I could tell Gradle to not generate these accessors for my build convention plugins? Or is there some smart way of telling Gradle to only package those accessors that are actually used?
    🤯 1
    m
    v
    +2
    • 5
    • 12
  • k

    Ken Yee

    02/07/2025, 9:47 PM
    With a gradle project without modules (build.gradle.kts and settings.gradle.kts at root), is there any reason the java{} and sourcesSets{} and dependencies DSL would be highlighted red? Most gradle projects have submodules, but this one does not because it's a mixed kotlin/groovy project 😞
    v
    i
    • 3
    • 6
  • a

    Adrian

    03/31/2025, 1:24 PM
    Hi, I thought I've seen some documentations in the past where Kotlin DSL is not recommended to be used to define Binary Plugins, but I can't seem to find it anymore 🤔 Are there any concerns in using Kotlin DSL methods within Binary Plugins today?
    Copy code
    // Without Kotlin DSL
    project.tasks.named("helloWorld", HelloWorldTask::class.java)
    
    // With Kotlin DSL
    import org.gradle.kotlin.dsl.named
    project.tasks.named<HelloWorldTask>("helloWorld")
    j
    t
    y
    • 4
    • 3
  • a

    André Martins

    04/07/2025, 2:06 PM
    Hey all, I'm trying to add an additional source set to a JvmTestSuite I have the following and it looks like I cannot reference any classes from that source set in the one created for the JvmTestSuite
    Copy code
    testing {
        suites {
            getByName<JvmTestSuite>("functionalTest") {
                sources {
                    kotlin.srcDir(layout.buildDirectory.dir("generated/api/src/main/kotlin"))
                }
                dependencies {
                    ...
                }
            }
        }
    }
    v
    • 2
    • 24
  • m

    Maksym Moroz

    04/08/2025, 12:36 PM
    What's the idiomatic way of enabling experimental kotlin features like
    when guard statements
    for a gradle project (module)?
    e
    • 2
    • 3
  • s

    Sebastian Schuberth

    04/08/2025, 4:08 PM
    Any hint how
    val jar by tasks.getting(Jar::class)
    behaves if there are multiple Jar tasks in the project? I could not find any docs on that.
    p
    c
    • 3
    • 9
  • k

    Ken Yee

    04/09/2025, 7:25 PM
    Trying to follow this to configure unit tests so I can see which one it was executing before it throws "Process 'Gradle Test Executor 38' finished with non-zero exit value 134": https://docs.gradle.org/8.12.1/userguide/java_testing.html#sec:java_testing_basics
    Copy code
    tasks.named<Test>("test") {
        useJUnit()
    
        beforeTest {
            logger.lifecycle("Running unit test: $it")
        }
    }
    It wants a closure instead for the beforeTest bit:
    Argument type mismatch: actual type is 'Function0<Unit>', but '(Closure<Any!>..Closure<*>?)' was expected.
    How do you specify a closure in kotlin-dsl?
    a
    v
    • 3
    • 7
  • c

    Claude Brisson

    04/26/2025, 9:01 AM
    Because of dependencies propagation from the
    buildSrc
    directory, it looks like I have to define an explicit version for the
    kotlin-dsl
    plugin in it. If I don't, I get the following error:
    Copy code
    Error resolving plugin [id: 'org.jetbrains.kotlin.multiplatform', version: '2.1.0', apply: false]
    > The request for this plugin could not be satisfied because the plugin is already on the classpath with an unknown version, so compatibility cannot be checked.
    But this plugin seems to have its own versioning scheme, and it's not clear to me which version to specify for a given gradle version (8.8 as it stands) and a given kotlin version (2.1.0). Is this documented somewhere?
    m
    v
    • 3
    • 25