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

Build Configurations based on App Variant (BuildType + Flavor)

I am trying to set signingConfig, manifestPlaceholders, buildConfigField for Application variant. I can set them for each buildType or! productFlavor independently, but what i need is to set them based on both productFlavor and!…
Jemshit
  • 9,501
  • 5
  • 69
  • 106
9
votes
2 answers

Configure plugin in separate file using Kotlin DSL

to differenciate diferent plugins configurations, I use separate files. For example: ./build.gradle.kts ./detekt.gradle.kts ./settings.gradle.kts ./module1 ./module2 ... In the root build.gradle.kts I have this: plugins { …
allnex
  • 335
  • 3
  • 12
9
votes
4 answers

Convert to gradle-kotlin-dsl Jfrog.Artifactory config

I'm trying to migrate from groovy to gradle-kotlin dsl, but I'm new to it, so I dont know how to configure Jfrog Artifactory. Please help me with converting that part of code to gradle-kotlin dsl: task sourceJar(type: Jar) { from…
Vadim Pikha
  • 336
  • 2
  • 9
9
votes
2 answers

How to conditionally accept Gradle build scan plugin terms of service in Kotlin DSL?

This basically extends this question to Kotlin DSL instead of Groovy DSL: How does the Groovy DSL solution of if (hasProperty('buildScan')) { buildScan { termsOfServiceUrl = 'https://gradle.com/terms-of-service' …
sschuberth
  • 28,386
  • 6
  • 101
  • 146
9
votes
2 answers

Android Studio cannot open Android project with Kotlin DSL

I have converted one of our Android projects from the old Groovy settings.gradle and build.gradle files to the new Kotlin DSL, i. e. settings.gradle.kts and build.gradle.kts. While "it works on my machine" - in particular: the original project I…
9
votes
1 answer

Make environment variables accessible to Gradle task

I need to run a Gradle task inside a shell environment, which must be created before the task is launched. Using commandLine or executable is not appropriate, as I need to run the task in the same process as the shell script. Originally, I called…
breandan
  • 1,965
  • 26
  • 45
8
votes
1 answer

KMM Project: Expected class has no actual declaration in module for JVM

I have a KMM project that is working perfectly except Android Studio gives an error on every expect function/value in my project complaining the actual version of it doesn't exist for JVM. The A in a yellow diamond to the side of it shows both the…
8
votes
0 answers

How to configure KMM project to support different buildTypes

When I switch build variants I got compilation error, but the problem is only for non default build variants (debug & release). So if I define customBuild { } and then choose that one, it fails with this error log: The consumer was configured to…
8
votes
1 answer

Define global configuration variables in KMM

In native android project, we can define BuildConfig variables which can be change based on the selected build type (debug or release). For this we can add the code below in app level gradle file buildTypes { release { buildConfigField…
S Haque
  • 6,881
  • 5
  • 29
  • 35
8
votes
0 answers

What exactly is "The plugins {} block must not be used here. If you need to apply a plugin imperatively"?

I have a gradle project that uses kotlin dsl: plugins { base kotlin("jvm") version "1.3.70" apply false } //val scalaV: String by project //val ext = SpikeExt(this) allprojects { apply(plugin = "java") apply(plugin = "scala") …
tribbloid
  • 4,026
  • 14
  • 64
  • 103
8
votes
1 answer

Gradle: share repository configuration between settings.gradle.kts and buildSrc/build.gradle.kts

There is a Gradle 6.X multi-module project using Kotlin DSL. buildSrc feature is used to manage dependency versions in a central place. Something similar to the approach described here. The project uses an internal server to download…
yuppie-flu
  • 1,270
  • 9
  • 13
8
votes
1 answer

0% Coverage in the SonarQube report for the Kotlin project

I'm setting up analyzing the a project by a SonarQube server. The used tool set is: Kotlin 1.3.61 Gradle 6.0.1 Jacoco 0.7.9 SonarQube 7.5 SonnarQube Gradle Plugin 2.7 The problem is that I have 0.0% coverage in SonarQube, however, in the same time…
8
votes
3 answers

build.gradle.kts & multi-module-project: how to add other project so that transitive dependencies are available too

Having the following multi-module-setup: multi ├── projA │ └── build.gradle.kts ├── projB │ └── build.gradle.kts ├── build.gradle.kts └── settings.gradle.kts with the following content (abbreviated): settings.gradle.kts rootProject.name =…
Roland
  • 22,259
  • 4
  • 57
  • 84
8
votes
2 answers

Build folder not generating in android studio project

Migrated to gradle kotlin dsl and ever since running the project from android studio fails to generate a build folder and an apk. Build succeeds but installation fails with the message: The APK file…
Nishita
  • 870
  • 1
  • 9
  • 33
8
votes
2 answers

How to read a dotted Gradle property in Kotlin DSL?

I can read from gradle.properties with val myProperty by settings, and that's nice! But what if the property name contains dots? Consider the next gradle.properties…
sedovav
  • 1,986
  • 1
  • 17
  • 28