https://gradle.com/ logo
Docs
Join the conversationJoin Slack
Channels
android
caching
community-news
community-support
config-avoidance
configuration-cache
contributing
dependabot
dependency-management
design
design-specs
developer-productivity-engineering
docs
dpe-summit
feed
file-system-watching
flutter
general
gradle-enterprise
jobs
kotlin-dsl
linen
maven
migrating-from-ant
migrating-from-maven
native
performance
playframework
plugin-development
releases
roadmap
self-promotion
Powered by Linen
kotlin-dsl
  • b

    Ben Madore

    10/05/2022, 8:36 PM
    does anyone know of a kts linting type tool that can be configured to fail on disallowed idioms in *.kts files. For instance, say, if i wanted to force developers to only use dependencies from a catalog and not in-line them e.g. allow:
    implementations(libs.mylibrary.foo)
    disallow:
    implementation("com.myorg.mylibrary:foo:1.2.3")
    v
    • 2
    • 1
  • t

    Tevin Jeffrey

    10/10/2022, 11:03 PM
    I see Gradle launches a Kotlin daemon for compiling build scripts using a version of Kotlin that was shipped with Gradle. In my case Gradle 7.5.1 is bundled with Kotlin 1.6.21. The problem is that if my project uses a different version of Kotlin, 1.7.10, incompatible with the one shipped with Gradle. During a build, there will be 2 daemon processes, one (1.7.10) actively compiling code during the execution phase and another (1.6.21) sitting around long after the configuration phase. Given my memory constraints I have a few questions: • Is there a way to configure the jvm arguments of the Gradle bundled Kotlin daemon separately from the daemon started by the Kotlin plugin? • Is there a way to configure the version of the Kotlin used to compile build scripts. • Can the build script daemon be stopped once the configuration phase is over?
    t
    • 2
    • 1
  • e

    efemoney

    10/13/2022, 2:15 AM
    Bringing up the topic of settings script accessors (for kotlin DSL) 😞. Is there any tracking issue or plans around this? With 7.6 and the new toolchainManagement APIs I see Gradle added the “fake”
    toolchainManagement.jvm
    extension function and imo its kinda weird to have an API that is available but fails the build by default. More and more plugin authors are encouraged to write and publish settings plugins but the experience of using these with the kotlin DSL is quite bad.
    j
    • 2
    • 2
  • j

    Javi

    10/14/2022, 10:43 PM
    Based on this https://github.com/Kotlin/KEEP/issues/309#issuecomment-1277778011 which implies creating a compiler plugin, is it possible in the future to use FIR in that plugin in order to generate the accessors for the applied plugins too?
    e
    a
    • 3
    • 6
  • v

    Vladimir Sitnikov

    10/19/2022, 12:05 PM
    There’s an interesting update regarding Kotlin lambdas: https://youtrack.jetbrains.com/issue/KT-15514/Annotate-blocks-that-are-being-executed-ou[…]he-current-call-frame-and-warn-on-captured-vars-into-them They consider adding the notion of “non-local lambdas”. I am not sure it helps Gradle directly, however, it might be it would prevent cases like “forgotten
    doLast
    ”
  • m

    Martin

    11/04/2022, 11:36 AM
    When using Kotlin build script, very often (if not always?) the auto-import uses inline imports, (i.e. adds
    com.example.FooExtension
    ) instead of importing it at the top of the file (
    import com.example.FooExtension
    ). Is it possible to tweak this?
    n
    • 2
    • 8
  • t

    Taylor Smith

    11/04/2022, 5:24 PM
    Hey everyone! I've run into somewhat of a dead end. I'm trying to publish a conventions plugin for boilerplate in our multi-module projects. The plugin works, but
    project.findProperty()
    does not work in the
    subproject
    scope. Same code works fine when applied directly to the subprojects, but not when using the
    subprojects
    block and applying it to the
    rootProject
    subprojects {
        apply(plugin="com.google.cloud.tools.jib")
        apply(plugin="maven-publish")
        apply(plugin="com.jfrog.artifactory")
    
        artifactory {
            setContextUrl("<https://my.jfrog.io/company/>")
    
            publish {
                repository {
                    setProperty("repoKey", "mvn-local")
                    setProperty("maven", true)
                    // Set these in your $HOME/.gradle/gradle.properties:
                    setProperty("username", project.findProperty("ARTIFACTORY_USER"))
                    setProperty("password", project.findProperty("ARTIFACTORY_PASSWORD"))
                    defaults(delegateClosureOf<groovy.lang.GroovyObject> {
                        invokeMethod("publications", "mavenJava")
                        setProperty("publishPom", true)
                        setProperty("publishArtifacts", true)
                    })
                }
            }
    
            resolve {
                setProperty("repoKey", "mvn-local")
            }
        }
    c
    v
    • 3
    • 52
  • c

    CristianGM

    11/10/2022, 5:00 PM
    Which folder or folders should I copy if I want to reuse compiled scripts? (so I can reduce
    Script compilation
    time)
    p
    c
    • 3
    • 31
  • r

    Rooz

    11/10/2022, 10:06 PM
    New Kotlin DSL training class offered by the Gradle team. Its free. please sign up and give us your feedback https://gradle.com/training/configuring-gradle-build-tool-with-kotlin/?time=1670371200
  • p

    Paul Merlin

    11/17/2022, 3:49 PM
    FYI IntelliJ 2022.3 actually in beta, comes with drastic performance improvement for IDE assistance in the
    .gradle.kts
    editor. Code completion is fast! 🚀 This work by the Kotlin Team changes the UX so much ❤️ https://blog.jetbrains.com/idea/2022/11/intellij-idea-2022-3-beta-2/#Improved_IDE_performance_for_Kotlin
    intellij-2022-3.mp4
    r
    j
    +2
    • 5
    • 8
  • c

    Claude Brisson

    11/18/2022, 2:31 PM
    Hi, community. I have a multimodule project [here](https://gitlab.republicate.com/claude/skorm), most submodules are kotlin libraries except a java library submodule, and the problem I encounter is that [this submodule](https://gitlab.republicate.com/claude/skorm/-/blob/main/skorm-jdbc/build.gradle.kts) publish plugin doesn't find anything to publish:
    ./gradlew -i :skorm-jdbc:publishToMavenLocal
    [...]
    > Task :skorm-jdbc:publishToMavenLocal
    Skipping task ':skorm-jdbc:publishToMavenLocal' as it has no actions.
    I'm using 7.5.1.
    g
    v
    • 3
    • 16
  • s

    Slackbot

    11/18/2022, 2:34 PM
    This message was deleted.
  • a

    Amanda

    11/29/2022, 10:26 PM
    We have a 90 min Configuring Gradle Build Tool with Kotlin Course scheduled for Dec 7th. It is geared towards people new to Gradle and want to start with the Kotlin DSL. This is the first run of the course, more to come later in different time zones. Feel free to share with people you think might need it!
  • ł

    Łukasz Wasylkowski

    12/05/2022, 11:00 AM
    Is there a changelog for https://plugins.gradle.org/plugin/org.gradle.kotlin.kotlin-dsl anywhere? 🤔 Linked repository redirects to https://github.com/gradle/kotlin-dsl-samples which is deprecated
    n
    p
    • 3
    • 17
  • t

    Taylor Smith

    12/15/2022, 10:17 PM
    hey again! Had a quick question and found somebody else attempting to do the same thing: https://stackoverflow.com/questions/70870791/configure-default-properties-in-gradle-precompiled-plugin
    v
    • 2
    • 12
  • p

    Pierre Ayfri

    12/30/2022, 9:16 AM
    Hi, what is the difference between this
    kotlin {
    	jvmToolchain(17)
    }
    And this
    tasks.withType<KotlinCompile> {
    	kotlinOptions.jvmTarget = "17"
    }
    ?
    m
    j
    +2
    • 5
    • 26
  • s

    ScalaWilliam

    01/08/2023, 1:24 PM
    Hi! I'm new to Gradle, coming from the Scala/SBT world. In SBT, if you define a file
    /project/Definitions.scala
    , you can reference the objects/values defined in that file from the main build file
    /build.sbt
    . How can this be done in Gradle-Kotlin?
    e
    b
    • 3
    • 5
  • n

    nissa faheem

    01/17/2023, 10:08 AM
    Hello! I am stuck with this issue: I have tried updating gradle and kotlin and everythng. Nothing works! Happens whenever I add compose dependency! PLease help! :'( Execution failed for task ':app:prepareDebugKotlinCompileTask'.
    org/jetbrains/kotlin/gradle/tasks/KotlinCompile
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:prepareDebugKotlinCompileTask'. Caused by: java.lang.NoClassDefFoundError: org/jetbrains/kotlin/gradle/tasks/KotlinCompile at com.android.build.gradle.tasks.PrepareKotlinCompileTask.doTaskAction(PrepareKotlinCompileTask.kt:65) at com.android.build.gradle.internal.tasks.NonIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(AndroidVariantTask.kt:74) at com.android.build.gradle.internal.tasks.NonIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(AndroidVariantTask.kt:34) at com.android.build.gradle.internal.tasks.Blocks.recordSpan(Blocks.java:91) at com.android.build.gradle.internal.tasks.NonIncrementalTask.taskAction(NonIncrementalTask.kt:5 org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:399) at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:157) at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:242) at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:150) at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:94) at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52) at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:41) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:356) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343) at Caused by: java.lang.ClassNotFoundException: org.jetbrains.kotlin.gradle.tasks.KotlinCompile (edited)
    v
    • 2
    • 1
  • f

    Farshid Fakhri

    01/21/2023, 1:10 AM
    https://gradle-community.slack.com/archives/CAHSN3LDN/p1674240071722459?thread_ts=1674240071.722459&amp;cid=CAHSN3LDN
  • j

    John

    02/01/2023, 7:09 PM
    I am having trouble using
    public inline fun <T : org.gradle.api.artifacts.ModuleDependency> org.gradle.api.artifacts.dsl.DependencyHandler.add(configuration: kotlin.String, dependency: T, dependencyConfiguration: T.() -> kotlin.Unit): T { /* compiled code */ }
    
    public inline fun org.gradle.api.artifacts.dsl.DependencyHandler.add(configuration: kotlin.String, dependencyNotation: kotlin.String, dependencyConfiguration: org.gradle.api.artifacts.ExternalModuleDependency.() -> kotlin.Unit): org.gradle.api.artifacts.ExternalModuleDependency { /* compiled code */ }
    🧵
    v
    • 2
    • 10
  • m

    Mark Maxey

    02/10/2023, 10:57 PM
    Hey everyone - I'm having trouble defining a reusable DSL variable. Using the examples found in Groovy closures from Kotlin , I can get reuse for any `Action`:
    val dependencyArtifact = Action<DependencyArtifact> { name = "artifact-name" }
            project.dependencies { add("implementation", "group:artifact:1.2.3") { artifact(dependencyArtifact) } }
    but I can't quite find the syntax for things that take a `Closure`:
    val bintray = BintrayExtension(project) // I constructed it like this purely as an example knowing this isn't the way you'd do it in real life.
            val bintrayPackageConfig = Closure<BintrayExtension.PackageConfig> { repo = "repossessed" } // WRONG! How do I populate a type specific Closure?
            bintray.pkg(closureOf<BintrayExtension.PackageConfig> { repo = "repossessed" })
            bintray.pkg(bintrayPackageConfig)
    Note I'm not using either
    closureOf<T> {}
    using
    delegateClosureOf<T> {}
    . Since I haven't tried to run it yet, perhaps my first
    Action
    example only compiles but doesn't work at runtime. The second
    Closure
    example doesn't compile because the
    Closure
    doesn't know what a
    repo
    is. It doesn't give me confidence when I see documentation like this:
    There sometimes isn’t a good way to tell, from looking at the source code, which version to use. Usually, if you get a
    NullPointerException
    with
    closureOf<T> {}
    , using
    delegateClosureOf<T> {}
    will resolve the problem.
    v
    • 2
    • 4
  • i

    Igor Wojda

    02/13/2023, 4:16 PM
    Hello I am struggling with defining a custom source set
    integrationTest
    . I am unable to access the
    CommandProcessor
    class defined in the
    main
    source set inside
    integrationTest
    source set. My goal is to use code from
    main
    source set (but not
    test
    source set) and use prod classes to run some tests. What am I missing here? build.gradle.kts:
    plugins {
        kotlin("jvm") version "1.8.0"
    }
    
    group = "org.example"
    version = "1.0-SNAPSHOT"
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation(kotlin("reflect"))
        implementation("io.insert-koin:koin-test-junit5:3.3.3")
    
        testImplementation(kotlin("test-junit5"))
        testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
        testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.2")
        testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
        testImplementation("io.mockk:mockk:1.13.2")
        testImplementation("org.amshove.kluent:kluent:1.72")
    }
    
    val integrationTest: SourceSet by sourceSets.creating
    configurations[integrationTest.implementationConfigurationName].extendsFrom(configurations.testImplementation.get())
    configurations[integrationTest.runtimeOnlyConfigurationName].extendsFrom(configurations.testRuntimeOnly.get())
    
    tasks.test {
        useJUnitPlatform()
    }
    
    val integrationTestTask = tasks.register<Test>("integrationTest") {
        description = "Runs integration tests."
        group = "verification"
        useJUnitPlatform()
    
        testClassesDirs = integrationTest.output.classesDirs
        classpath = configurations[integrationTest.runtimeClasspathConfigurationName] + integrationTest.output
    }
    a
    v
    • 3
    • 3
  • b

    Benjamin Muschko

    02/13/2023, 4:53 PM
    i am trying to determine if it makes sense to switch over from the groovy DSL to the kotlin DSL solely for performance reasons. can the gradle team provide some numbers here? the numbers in https://github.com/gradle/gradle/issues/15886 are outdated.
    l
    v
    +3
    • 6
    • 21
  • p

    pshakhov

    02/14/2023, 7:57 AM
    Hello. How i can access 'buildSrc' module via dsl? By
    project.relativePath
    or
    resolve
    , or any way like
    project.subprojects
    (some another entity like subprojects)?
    v
    l
    m
    • 4
    • 5
  • j

    John

    02/15/2023, 1:20 AM
    I found myself wanting this and was wondering if it would be accepted upstream in TaskContainerExtensions in kotlin-dsl
    /**
     * A version of maybeCreate that allows you to pass a configuration lambda that will only run when the task is created
     */
    inline fun <reified U : Task> TaskContainer.maybeCreate(name: String, noinline config: U.() -> Unit): U {
        val existing: Task? = findByName(name)
        return if (existing != null) {
            Transformers.cast<U, Any>(U::class.java).transform(existing)
        } else {
            create(name, U::class.java, config)
        }
    }
    j
    e
    • 3
    • 2
  • i

    Igor Wojda

    02/17/2023, 9:58 PM
    I have this
    detektBase
    task that is used to run
    detekt
    . Based on the
    autoCorrect
    param this task either run checks or run checks and applies auto correct.
    tasks.register("detektBase", Detekt::class) {
        val autoCorrectParam = project.hasProperty("autoCorrect")
    
        description = "Custom detekt for to check all modules"
        autoCorrect = autoCorrectParam
    
        //bunch of other detekt config params
    }
    How can I split this into two separate tasks?
    tasks.register("detektCheck", Detekt::class) {
        //call detektBase with autoCorrectParam false
    }
    
    tasks.register("detektApply", Detekt::class) {
        //call detektBase with autoCorrectParam true
    }
    v
    • 2
    • 3
  • s

    Shalom Ben-Zvi Kazaz

    02/18/2023, 6:55 PM
    can someone please help me write that in kotlin dsl. its from this article https://www.baeldung.com/spring-boot-auto-property-expansion
    import org.apache.tools.ant.filters.ReplaceTokens
    processResources {
        with copySpec {
            from 'src/main/resources'
            include 'application.properties'
            project.properties.findAll().each {
              prop ->
                if (prop.value != null) {
                    filter(ReplaceTokens, tokens: [ (prop.key): prop.value])
                    filter(ReplaceTokens, tokens: [ ('project.' + prop.key): prop.value])
                }
            }
        }
    }
    f
    a
    +2
    • 5
    • 11
  • l

    Luc-Antoine Girardin

    02/24/2023, 7:34 PM
    Is it possible to load properties from a custom
    .properties
    file (say for example
    custom.properties
    ) from
    settings.gradle.kts
    , and use those properties in a module's
    build.gradle.kts
    ?
    v
    a
    • 3
    • 3
  • k

    Kalpesh Chandora

    02/27/2023, 7:00 AM
    Is there a way to determine whether a shell script is running from Android Studio terminal or from Github Actions?
    v
    p
    • 3
    • 5
  • b

    Benoît

    03/13/2023, 12:57 PM
    Hey all, I’m having an exception on configuration:
    A problem occurred configuring root project 'wire'.
    > Could not determine the dependencies of null.
       > Could not resolve all dependencies for configuration ':classpath'.
          > Dependencies can not be declared against the `testCompileClasspath` configuration.
    Using the debugger I found the failure:
    org.gradle.internal.resolve.ArtifactNotFoundException: Could not find org.gradle.kotlin.kotlin-dsl.gradle.plugin-4.0.6.jar (org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:4.0.6).
    The coordinates don’t look right to me, why is the name including the group again? I started getting this error having bumped a few dependency versions including gradle from
    7.4
    to
    8.0.2
    I’m not setting explicitely this dependency anyway and I’m a bit stuck. Would anyone know what is up?
    v
    • 2
    • 5
Powered by Linen
Title
b

Benoît

03/13/2023, 12:57 PM
Hey all, I’m having an exception on configuration:
A problem occurred configuring root project 'wire'.
> Could not determine the dependencies of null.
   > Could not resolve all dependencies for configuration ':classpath'.
      > Dependencies can not be declared against the `testCompileClasspath` configuration.
Using the debugger I found the failure:
org.gradle.internal.resolve.ArtifactNotFoundException: Could not find org.gradle.kotlin.kotlin-dsl.gradle.plugin-4.0.6.jar (org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:4.0.6).
The coordinates don’t look right to me, why is the name including the group again? I started getting this error having bumped a few dependency versions including gradle from
7.4
to
8.0.2
I’m not setting explicitely this dependency anyway and I’m a bit stuck. Would anyone know what is up?
v

Vampire

03/13/2023, 1:03 PM
That is the marker artifact that is used to resolve a plugin ID from a plugin in the
plugins { ... }
block to an actual code artifact. That is perfectly fine and will also be found if you have the Gradle Plugin Portal or any other repository where it is present as plugin repository. The error
Dependencies can not be declared against the `testCompileClasspath` configuration.
on the other hand means that you try to declare a dependency for
testCompileClasspath
which you shouldn't do and is checked with Gradle 8 now. You should declare it against
testImplementation
,
testApi
, or
testCompileOnly
instead. For
kotlin-dsl
most probably
testCompileOnly
.
b

Benoît

03/13/2023, 1:04 PM
I don’t have any
testCompileClasspath
in my project and I cannot find where it’s set
The trace shows me it happens on
buildSrc
it seems. I’ll see if I can get rid of it as I don’t use it for now
v

Vampire

03/13/2023, 1:06 PM
Maybe you use some plugin that does it. When upgrading Gradle, I usually recommend to first update to the latest minor release of a major version (7.6.1 in your case) and fix all deprecation warnings before going to the next major version. Usually if there are no deprecation warnings, the build should work with the next major version.
b

Benoît

03/13/2023, 2:35 PM
I’ve rolled back some version bumps and I’m ok for now. Thank you. I’ll try again soon. Thanks for the tips
View count: 4