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
13
votes
1 answer

Adds an implementation dependency only to the "free" product flavor in Kotlin DSL

I am in process of migrating our Groovy based scripts to Kotlin. I have been able to get most of done except not sure how to add a dependency for a particular flavour. This is how looks like in Kotlin DSL so far but not sure why the…
Bulu
  • 1,351
  • 3
  • 16
  • 37
13
votes
2 answers

How to build a runnable ShadowJar with a gradle script Kotlin build file?

Simplest possible Kotlin hello world for gradle script Kotlin: thufir@dur:~/github/gradleScriptKotlin$ thufir@dur:~/github/gradleScriptKotlin$ gradle clean shadowJar;java -jar build/libs/gradleScriptKotlin.jar > Task :compileKotlin Using Kotlin…
Thufir
  • 8,216
  • 28
  • 125
  • 273
13
votes
3 answers

How to configure the processResources task in a Gradle Kotlin build

I have the following in a groovy-based build script. How do I do the same in a kotlin-based script? processResources { filesMatching('application.properties'){ expand(project.properties) } }
KevinS
  • 7,715
  • 4
  • 38
  • 56
12
votes
3 answers

Intellij is erroring when reading my build.gradle.kts file

The red notification bar at the top says: /org/gradle/tooling/BuildException (java.lang.NoClassDefFoundError: /org/gradle/tooling/BuildException. I can run a gradle refresh successfully, I can run the project successfully, but I cannot get that…
Sam
  • 401
  • 5
  • 13
12
votes
1 answer

Reuse gradle.kts function

I have a multiproject gradle.kts setup and I would like to reuse a function, eg. fun doSomethingWithString(string: String) { return string } I then use the function within the dependencies {} block. I would like to either: define the fun within…
Vojtěch
  • 11,312
  • 31
  • 103
  • 173
12
votes
3 answers

Android specific flavor dependency via Kotlin DSL

Inside build.gradle we could productFlavors { free { dimension "tier" } } Then dependencies { freeDebugImplementation "com.someDependency:free-debug:1.0.0";} BUT when I use Kotlin DSL, inside build.gradle.kts, I…
Neil G
  • 203
  • 1
  • 7
12
votes
2 answers

Is there a way to define property to be used in both settings.gradle.kts and projects/subprojects build.gradle.kts with gradle 6.0?

We have multi-module android app with build logic written in gradle kotlin dsl. We use buildSrc to extract common logic like dependencies versions. We have something like: buildSrc/src/main/kotlin/Dependencies.kt: object Versions { const val…
ferini
  • 1,908
  • 14
  • 17
12
votes
1 answer

How to define Gradle project properties with Kotlin DSL

I'd like to check if two project properties are set and if not, set them to empty values in order to avoid a build failure. These properties are supposed come from ~/.gradle/gradle.properties (if configured). The goal is to have credentials to a…
chrset
  • 581
  • 6
  • 11
12
votes
2 answers

How to pass command line argument to Gradle Kotlin DSL

Here's an example from Groovy that represents exactly what I would like to achieve: Command line: ./gradlew jib -PmyArg=hello build.gradle.kts task myTask { doFirst { println myArg ... do what you want } } Source of this…
skryvets
  • 2,808
  • 29
  • 31
12
votes
2 answers

Android build fails with R8

Build is failing with the following error upon enabling R8 on android studio 3.4-RC3. Build is successful if android.enableR8=false Undefined value encountered during compilation. This is typically caused by invalid dex input that uses a register…
Nishita
  • 870
  • 1
  • 9
  • 33
12
votes
3 answers

Unresolved references of buildSrc kotlin constants after migration to gradle kotlin dsl

I´m trying to migrate my android project to using gradle kotlin dsl, replacing all build.gradle files with build.gradle.kts files and using kotlin there. Already before, I used to have a kotlin file containing object elements with library and…
Lemao1981
  • 2,225
  • 5
  • 18
  • 30
12
votes
1 answer

Gradle Kotlin DSL equivalent for Groovy DSL compilerArgs for compileJava

For the Gradle Java plugin, what is the Kotlin DSL equivalent for the following Groovy DSL? compileJava { options.compilerArgs += ['-Xdoclint:all,-missing', '-Xlint:all'] }
XDR
  • 4,070
  • 3
  • 30
  • 54
11
votes
2 answers

Unresolved reference: ext when convert gradle to gradle.kts

By default when I create a compose app from Android Studio, it will give me ext as below in my root project build.gradle. buildscript { ext { compose_version = '1.0.0' } repositories { google() mavenCentral() …
Elye
  • 53,639
  • 54
  • 212
  • 474
11
votes
0 answers

Using Gradle plugin from composite build in root project buildscript

I use Gradle Kotlin DSL and in my project I have separate build-dependencies gradle module which is included in settings.gradle.kts like so: pluginManagement { repositories { google() jcenter() gradlePluginPortal() …
pavelkorolevxyz
  • 1,380
  • 2
  • 14
  • 35
11
votes
1 answer

Gradle test fixtures plugin and core module dependencies

I have a project built with Gradle version 6.4 and JDK 8. I'm trying to use the Gradle plugin for Test Fixtures (java-test-fixtures) but I have some issues with the dependencies. According to the Gradle page linked above, the project should be…