Questions tagged [gradle-kotlin-dsl]

Kotlin language support for Gradle build scripts.

Gradle build scripts have historically been written in Groovy. The Gradle Kotlin DSL project was created to create statically typed, clear, concise,and descriptive build scripts with awesome IDE support.

Build scripts are written in the Kotlin programming language, but using a Kotlin DSL (domain specific language) designed specifically to support building software.

Questions that belong here:

  • What causes a specific build script error?
  • How to convert a specific construct of a Groovy build script to its Kotlin equivalent?
  • How to achieve a specific processing task in your Kotlin build script?

Do not use this tag for general gradle questions.

Note: Before version 0.10.1 the "Gradle Kotlin DSL" project was called "Gradle Script Kotlin".

1145 questions
29
votes
2 answers

Error: "Unresolved reference: versionCode" in build.gradle.kts

I'm trying to add a new module (library module) to my project but in build.gradle.kts (for library module) I have this error: org.gradle.internal.exceptions.LocationAwareException: Build file ' ... /build.gradle.kts' line: 13 Script compilation…
Ehsan msz
  • 1,774
  • 2
  • 13
  • 26
29
votes
2 answers

Convert an existing groovy build.gradle file into a kotlin based build.gradle.kts

my project has two different build.gradle files written with groovy Syntax. I´d like to change this groovy written gradle file into a gradle file written with Kotlin Syntax (build.gradle.kts). I´ll show you the root project build.gradle file. //…
Exitare
  • 561
  • 2
  • 10
  • 30
27
votes
2 answers

buildFeatures is unstable because its signature references unstable ... marked with @Incubating

Updating Android studio project and migrating to Kotlin dsl. I see the above warning wrapping the buildFeatures block where i enable dataBinding and more recent viewbinding features, my AS and gradle, kotlin plugin versions are as below: Android…
Jamal S
  • 1,649
  • 1
  • 19
  • 24
25
votes
2 answers

Gradle includeBuild vs implementation project

What is the key difference between includeBuild(...) and implementation(project(...)) in the Gradle build system? I cannot really see the usecase difference after reading the…
Jan Veselý
  • 1,329
  • 1
  • 15
  • 24
25
votes
2 answers

How to parametrize Kotlin version in the plugins block of a build.gradle.kts script?

In the script below: val kotlinVersion by extra ("1.3.61") println("Version "+kotlinVersion) plugins { kotlin("jvm") version kotlinVersion } The variable kotlinVersion is correctly printed. Nevertheless it is not recognized in the plugins…
Emile Achadde
  • 1,715
  • 3
  • 10
  • 22
24
votes
1 answer

How to add new configuration with Gradle Kotlin-dsl

with gradle-groovy it is possible to create a new configuration with: configurations { explode } dependencies { explode (group: 'org.apache.samza', name: 'samza-shell', ext: 'tgz', classifier: 'dist', version: "$SAMZA_VERSION") } But I…
guenhter
  • 11,255
  • 3
  • 35
  • 66
23
votes
1 answer

What is difference between compileSdk and compileSdkVersion in android studio gradle script when using jetpack compose

When I created new android project with jetpack compose toolkit with or without kotlin dsl I found that in module level build.gradle file the property compileSdkVersion has been replaced by compileSdk. I also found that android sdk version…
23
votes
2 answers

How to define a variable for all Gradle subprojects using Gradle Kotlin DSL

I am following this guide. The guide reads: Extra properties on a project are visible from its subprojects. This does not seem to work for me, as the following does not work: In build.gradle.kts I have: val ktorVersion by extra("1.3.2") In…
Philippe
  • 1,715
  • 4
  • 25
  • 49
22
votes
2 answers

Gradle7 Version Catalog: How to use it with buildSrc?

I am very excited about the incubating Gradle's version catalogs and have been experimenting with it. I’ve found that the information in my gradle/libs.versions.toml is accessible in the build.gradle.kts scripts for my app and utility-lib…
A Bit of Help
  • 1,368
  • 19
  • 36
22
votes
3 answers

How to get ext.* variables into plugins block in build.gradle.kts

My build file looks like this: val nexusBaseUri: String by extra val gradle_version: String by extra val kotlin_version: String by extra buildscript { val nexusBaseUri by extra { "https://mynexusserver/nexus" } val gradle_version by extra {…
Andy
  • 8,749
  • 5
  • 34
  • 59
21
votes
2 answers

How to update the manifestPlaceholders in applicationVariants in Kotlin Gradle DSL?

I try to convert this to Kotlin: applicationVariants.all { variant -> def flavor = variant.productFlavors[0] def mergedFlavor = variant.getMergedFlavor() mergedFlavor.manifestPlaceholders = [applicationLabel:…
Herrbert74
  • 2,578
  • 31
  • 51
21
votes
5 answers

Integration tests with Gradle Kotlin DSL

I'm using this blog post to configure integration tests for a Spring Boot project, but I'm pretty stuck on declaring the source sets. I also found this post on StackOverflow, but I think I'm a bit further already. My project structure is project |_…
Johan Vergeer
  • 5,208
  • 10
  • 48
  • 105
21
votes
1 answer

How are gradle extra properties set in the Kotlin DSL?

I'm trying to organize my build files as I would in groovy, by having values in a separate file to reuse. But I cannot understand the syntax to do the same thing in the kotlin DSL. Here's what I'm using in root…
Daykm
  • 475
  • 1
  • 5
  • 13
20
votes
3 answers

Jetpack proto datastore - gradle config with Kotlin dsl

In jetpack datastore, you have to set the gradle plugin task for generating class out of .proto files: // build.gradle protobuf { protoc { artifact = "com.google.protobuf:protoc:3.10.0" } // Generates the java Protobuf-lite code…
Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117
20
votes
1 answer

Include scripts with Gradle Kotlin DSL

I'm trying to start using Kotlin DSL with gradle in the project with the following restrictions: Project has different modules (moreover: sometimes these modules use different plugins, however if two projects uses the same plugin then version of…
Manushin Igor
  • 3,398
  • 1
  • 26
  • 40
1 2
3
76 77