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
8
votes
3 answers

Expected class has no actual declaration

I am doing a multiplatform project. A part of my gradle file looks like this ... kotlin { jvm() jvm("api") js() mingwX64("mingw") sourceSets { ... val jvmMain by getting { dependencies { …
8
votes
3 answers

Defining dimensions in Kotlin DSL for gradle

I'm converting my build.gradle to Kotlin DSL. I have 2 build flavors in the app, and I can't figure out how to set the dimension for the flavors: flavorDimensions("type") productFlavors { create("free") { buildConfigField("boolean",…
Francesc
  • 25,014
  • 10
  • 66
  • 84
8
votes
1 answer

versionCodeOverride equivalent for Gradle Kotlin DSL

android.applicationVariants.all { variant -> variant.outputs.each { output -> int newVersionCode = android.defaultConfig.versionCode * 10 + abiVersionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) …
PhilipSa
  • 215
  • 2
  • 9
8
votes
1 answer

Gradle 5 Kotlin DSL: Common Tasks & Maven Artifacts in multi-modules projects

I really would like to appreciate Gradle 5 especially in combination with the new Kotlin DSL, but I’m having a very hard time to get (in my eyes) a very, very simple and common build running with Gradle. Task Release a Java library with several…
bentolor
  • 3,126
  • 2
  • 22
  • 33
8
votes
2 answers

How to define Jacoco report aggregation in Gradle Kotlin DSL?

In Gradle Groovy I was using task jacocoRootReport(type: JacocoReport) { dependsOn = subprojects.test subprojects.each { sourceSets it.sourceSets.main } executionData.from…
delor
  • 800
  • 1
  • 7
  • 19
8
votes
2 answers

Setting environment variables in build.gradle.kts

In groovy you can set environment variables with environment key value. For example for run you can do: run { environment DB_HOST "https://nowhere" } How can I accomplish this in Kotlin in build.gradle.kts?
Heinrisch
  • 5,835
  • 4
  • 33
  • 43
8
votes
2 answers

Kotlin buildSrc failing on Gradle 4.10 due to missing dependency

When upgrading to Gradle 4.10, I faced the following error when attempting to compile: Execution failed for task ':buildSrc:compileKotlin'. > Could not resolve all files for configuration ':buildSrc:kotlinCompilerPluginClasspath'. > Could not…
Juan Andrés Diana
  • 2,215
  • 3
  • 25
  • 36
8
votes
1 answer

sourceSets with gradle kotlin DSL in grade 4.10rc

I am using the following code: java.sourceSets["main"].java { srcDir("src/main/extraSource") } works perfectly in gradle 4.9, but in 4.10 rc1 gives the following error: Line 5: java.sourceSets["main"].java { ^ Unresolved…
innov8
  • 2,093
  • 2
  • 24
  • 31
8
votes
1 answer

IDEA reports errors in build.gradle.kts while command line gradle run succeeds

I am using Kotlin DSL with Gradle build tool. My gradle build works well both locally and on jenkins server when run from command line. However IDEA complains and marks several items red with the following errors: Cannot access class…
ludenus
  • 1,161
  • 17
  • 30
7
votes
1 answer

Is it possible for 2 submodules to have different paths but identical names?

example project (written in Gradle 8.1.1 with kotlin DSL): https://github.com/tribbloid/scaffold-gradle-kts/tree/16bf3acffca7b83a7e64dbb248a9512caba87e71 This project has 3+…
tribbloid
  • 4,026
  • 14
  • 64
  • 103
7
votes
1 answer

Gradle "There is no feature named VERSION_CATALOGS"

I am trying to upgrade Gradle version from 7.x to 8.x. However, when I completed my Gradle wrapper upgrade and ran the project I encountered the following error: Settings file '.../settings.gradle.kts' line: 7 There is no feature named…
u-ways
  • 6,136
  • 5
  • 31
  • 47
7
votes
3 answers

gRPC UnsupportedAddressTypeException, but only when packaged with shadowJar

I have a simple gRPC client packaged in a jar by Gradle with shadowJar. When I run the main() with IntelliJ, the RPC is sent successfully. When I run it with java -jar, I get an exception: Update: I think I've determined that the same set of classes…
7
votes
1 answer

LibraryExtension not found when using catalog version and kotlin dsl

I'm having trouble using Catalog Version in gradle, which I'm trying to apply to my project. I took an example from here https://github.com/android/nowinandroid but when I get an error like in : Extension of type 'LibraryExtension' does not exist.…
7
votes
1 answer

Android Gradle Plugin - what should I use in place of incubating abstractions, such as defaultConfig?

I am new to Gradle, and I'm trying to port my android groovy build script to kts. I have a working build, however Android studio is complaining (all over the place) about my syntax. For example: defaultConfig:…
hba
  • 7,406
  • 10
  • 63
  • 105
7
votes
1 answer

Why do I get "Unresolved reference: platform" when using the firebase-bom dependency with KMM

When I attempt to add the Firebase-bom dependency using the following block in a Kotlin Multiplatform Mobile (KMM) project's shared module, the word platform appears in red error text and the Gradle build fails with "Unresolved reference: platform."…
colintheshots
  • 1,992
  • 19
  • 37