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
19
votes
5 answers

Build source jar with Gradle Kotlin DSL?

This question asks how to build a SourceJar with Gradle. How can I do the same with the Gradle Kotlin DSL? The gradle code would be: task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' from…
Morgoth
  • 4,935
  • 8
  • 40
  • 66
18
votes
3 answers

How to run a command line command with Kotlin DSL in Gradle 6.1.1?

I am trying to run the code block below, after reading multiple posts on the topic and the Gradle manual. I run the below and get the following error: execCommand == null! Any ideas on what I am doing wrong with the below code block? open class…
Dan Largo
  • 1,075
  • 3
  • 11
  • 25
18
votes
1 answer

Kotlin DSL build scripts dependency updates

There has been a myriad of articles written about how migrating from using groovy scripts to using Kotlin DSL for Gradle dependency management is an ideal way to manage build scripts among other mentioned advantages. However, the limitation that I…
George
  • 2,865
  • 6
  • 35
  • 59
18
votes
4 answers

Reference property in Gradle Properties

My gradle.properties.kts files has the following contents: build_version=develop build_version_code=2 include_vas=false In my build.gradle.kts looks as follows: plugins { id(Plugins.androidApplication) kotlin(Plugins.kotlinAndroid) …
George
  • 2,865
  • 6
  • 35
  • 59
18
votes
1 answer

Kotlin DSL: Import a versions.gradle.kts into another build.gradle.kts

I have created a versions.gradle.kts just like that: object Defines { const val kotlinVersion = "1.2.61" const val junitVersion = "5.3.0" } Now I want to import and use that files like that: import…
Deglans Dalpasso
  • 495
  • 5
  • 14
17
votes
1 answer

How to use Firebase BoM in Kotlin Gradle dsl?

How does this look it kotlin DSL: dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:26.2.0') } The above is the current recommended at Firebase docs
arberg
  • 4,148
  • 4
  • 31
  • 39
17
votes
7 answers

could not find extension implementation class org.jetbrains.kotlin.idea.scripting.gradle.roots.GradleBuildRootsManager

My project works and builds successfully on my Mac but I cloned from github and although Android Studio appears to work normally, the project wouldn't build. I setup this project using Kotlin DSL. Gradle sync failed: could not find extension…
17
votes
2 answers

Using kapt with multiplatform subproject

I have the following project structure root-project │ build.gradle.kts │ └───multiplatform-project │ │ build.gradle.kts │ │ │ └───src │ │ kotlin | | js │ └───simple-kotlin-project │ build.gradle.kts So there are…
16
votes
3 answers

Unable to publish jar to Gitlab package registry with gradle

I am trying to publish some jar artefacts on gitlab package registry but I get this error from the server : Received status code 415 from server: Unsupported Media Type Here is the publishing section of my build.gradle.kts : publishing { …
Dimitri
  • 8,122
  • 19
  • 71
  • 128
16
votes
2 answers

isCoreLibraryDesugaringEnabled not works in gradle kotlin dsl / kts

To enable desugaring in our android-library module we must put this in build.gradle: android { compileOptions { coreLibraryDesugaringEnabled true } } But we have all scripts migrated to gradle kotlin dsl, so the problem occurs in…
Krystian Kaniowski
  • 1,959
  • 17
  • 33
16
votes
2 answers

How to create a "base" gradle file in Kotlin DSL for multi-module project?

To reuse code in gradle files I usually have a "base" gradle file for certain modules and just apply them and add whatever new dependencies it might need. I'm in the progress of converting all my gradle files to the new Kotlin DSL but I get…
Nicholas Doglio
  • 286
  • 3
  • 8
16
votes
2 answers

How to use plugin version from gradle.properties in Gradle Kotlin DSL?

Now I use this way: plugins { val kotlinVersion: String by project val springBootPluginVersion: String by project val springDependencyManagementPluginVersion: String by project id("org.jetbrains.kotlin.plugin.allopen") version…
Roman Q
  • 245
  • 3
  • 16
15
votes
5 answers

We recommend using a newer Android Gradle plugin to use compileSdkPreview = "Sv2" warning in android studio

When I am running an app in android studio using Android Sv2 Preview SDK, I am getting a warning: Build Output We recommend using a newer Android Gradle plugin to use compileSdkPreview = "Sv2" This Android Gradle plugin (7.2.0-alpha04) was tested…
Vidyesh Churi
  • 1,899
  • 1
  • 24
  • 33
15
votes
1 answer

How to set FlavorDimensions in AGP 7.0.0?

Since Android Studio Arctic Fox has reached stable recently, our team has decided to make the switch. However, we hit some roadblocks while upgrading our project to use the latest AGP, from 4.2.1 to 7.0.0 Below is our old…
You Qi
  • 8,353
  • 8
  • 50
  • 68
15
votes
1 answer

Unresolved reference: sourceSets for Gradle Kotlin DSL

Trying to migrate my existing build.gradle to Kotlin and I am getting the following error in my project: Script compilation error: Line 86: from(sourceSets["main"].allSource) ^ Unresolved reference: sourceSets 1…
Cisco
  • 20,972
  • 5
  • 38
  • 60