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

How can I specify a category for a Gradle task?

I am writing a Gradle task in Intellij IDEA. I have noticed that in the Gradle window, the tasks appear under folders like so: I am wondering, how can you give a task a 'category' so that it appears in a folder as shown in the screenshot? All the…
Mendhak
  • 8,194
  • 5
  • 47
  • 64
46
votes
3 answers

How do you add local .jar file dependency to build.gradle.kt file?

I have gone through similar questions regarding build.gradle and I have looked through the Gradle Kotlin Primer and I don't see how to add a .jar file to a build.gradle.kt file. I am trying to avoid using mavenLocal()
Naruto Sempai
  • 6,233
  • 8
  • 35
  • 51
43
votes
16 answers

Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.2.71'] was not found in any of the following sources

I have a fresh install of IntelliJ, I created a new kotlin gradle project using the following settings: This produces the following build.gradle.kts, (the exact same file works on my Windows machine): import…
Morgoth
  • 4,935
  • 8
  • 40
  • 66
43
votes
5 answers

How to access variant.outputFileName in Kotlin

We've been using a snippet like this one to rename the APK file generated by our Gradle build: android.applicationVariants.all { variant -> variant.outputs.all { outputFileName = "${variant.name}-${variant.versionName}.apk" …
david.mihola
  • 12,062
  • 8
  • 49
  • 73
43
votes
1 answer

Gradle: What is the benefit if I switch from Groovy to Kotlin?

I'm a Android developer. As result I use Gradle for build android projects. I write (about 2 years) gradle scripts on Groovy. As result scripts is very compact, clear and easy to support. It is very good. But in new version of Gradle is introduce…
Alex
  • 1,857
  • 4
  • 17
  • 34
42
votes
2 answers

What's the difference between .kt and .kts files in Kotlin. When should we use .kts file over .kt file?

What is the purpose of using .kts files in Kotlin? Are these files included in the app bundle when releasing the app?
Sweta Jain
  • 3,248
  • 6
  • 30
  • 50
42
votes
2 answers

What is the difference between registering and creating in Gradle Kotlin DSL

There are two methods of creating, i.e. tasks, in Gradle (5.0+): tasks { val javadocJar by creating(Jar::class) { val javadoc by tasks from(javadoc) classifier = "javadoc" } } and tasks { val javadocJar by…
madhead
  • 31,729
  • 16
  • 153
  • 201
41
votes
9 answers

How to add new sourceset with gradle kotlin-dsl

I want to add a sourceset src/gen/java. With groovy this is rather easy and already described in https://discuss.gradle.org/t/how-to-use-gradle-with-generated-sources/9401/5 sourceSets { gen { java.srcDir "src/gen/java" } } But I…
guenhter
  • 11,255
  • 3
  • 35
  • 66
39
votes
3 answers

How do I use the native JUnit 5 support in Gradle with the Kotlin DSL?

I want to use the built-in JUnit 5 with the Gradle Kotlin DSL, because during build I get this warning: WARNING: The junit-platform-gradle-plugin is deprecated and will be discontinued in JUnit Platform 1.3. Please use Gradle's native support for…
PHPirate
  • 7,023
  • 7
  • 48
  • 84
35
votes
4 answers

Unresolved reference: compileKotlin in build.gradle.kts

Kotlin project success build by build.gradle: compileKotlin { kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8 } compileTestKotlin { kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8 } Nice. But I need to change to build.gradle.kts: …
Alexei
  • 14,350
  • 37
  • 121
  • 240
33
votes
1 answer

Gradle KTS Build Files

Google released an updated version of Android Studio 3.5. After having updated to this version I get this warning below: This project uses Gradle KTS build files which are not fully supported. Some functions may be affected. However, I believe…
Mayur Patel
  • 2,300
  • 11
  • 30
32
votes
4 answers

Read value from local.properties via Kotlin DSL

I want to retreive key from local.properties file that looks like : sdk.dir=C\:\\Users\\i30mb1\\AppData\\Local\\Android\\Sdk key="xxx" and save this value in my BuildConfig.java via gradle Kotlin DSL. And later get access to this field from my…
i30mb1
  • 3,894
  • 3
  • 18
  • 34
31
votes
3 answers

How to exclude library from all dependencies in Kotlin DSL build.gradle?

I started migration from build.gradle (Groovy) to build.gradle.kts (Kotlin DSL). The thing is that com.google.common.util.concurrent.ListenableFuture (from com.google.guava) exists in several dependecies. Because of that build fails with…
Demigod
  • 5,073
  • 3
  • 31
  • 49
31
votes
2 answers

Can't use project extra properties in plugin block

I have a multi-project build, and more often than not I find myself locking versions for artifacts across the board. So in my root project I define something like: project.extra.set("pkgVersions", mapOf( "kotlin" to "1.2.0", "jooq" to…
Rohan Prabhu
  • 7,180
  • 5
  • 37
  • 71
31
votes
5 answers

Boilerplate project configuration in Gradle with Gradle Kotlin DSL

I'm currently trying to improve the way our projects share their configuration. We have lots of different multi-module gradle projects for all of our libraries and microservices (i.e. many git repos). My main goals are: To not have my Nexus…
James Bassett
  • 9,458
  • 4
  • 35
  • 68
1
2
3
76 77