Questions tagged [kotlin-dsl]

68 questions
2
votes
0 answers

How to call a Gradle task with arguments from another with Kotlin DSL?

I want to call default run task that needs arguments, from another task defined in build.gradle.kts. I can call run from another task but I do not know how to pass parameters.
Erdem Tuna
  • 500
  • 4
  • 18
2
votes
1 answer

How to reuse dependency versions in subprojects for Kotlin DSL?

I have a multi module Gradle project with Kotlin DSL as build file. Inside of the root build.gradle.kts there is dependencies section for root and subprojects with its own dependencies. I would like to create a variable that can keep version of some…
boden
  • 1,621
  • 1
  • 21
  • 42
2
votes
1 answer

How to import KotlinMultiplatformExtension inside buildSrc module?

I am developing a kotlin multiplatform project, which has a bunch of modules. I have written an extension function which is meant to be used inside each module. The extension function extends functionality of KotlinMultiplatformExtension class. Now…
RadekJ
  • 2,835
  • 1
  • 19
  • 25
2
votes
0 answers

Declaring a function that is not an expression in Kotlin

How can I force a compile-time error, when somebody tries to use a function as expression that is not intended to be used like that? fun someFunctionThatReturnsNothing() { println("Doing some stuff") } // this should give an error: val value =…
Mathias Henze
  • 2,190
  • 1
  • 12
  • 8
2
votes
1 answer

Error with Building Fatjar Using Kotlin DSL

I am trying to build a fatjar using ShadowJar. My app and gradle code are below. I'm using Gradle 5.0 for the build. When I run ./gradlew run, the code works. When I run 'gradle shadowjar', and run the fatjar using 'java -jar' in the 'build/lib'…
Dan Largo
  • 1,075
  • 3
  • 11
  • 25
1
vote
0 answers

Build gradle kotlin dsl task extension method

I want to modify my build.gradle.kts by implementing some tasks. Specially, I want to obtain the output of the first task in my second task, where the first task runs a shell command. There are some basic examples here and here, which are…
Hölderlin
  • 424
  • 1
  • 3
  • 16
1
vote
2 answers

gradle where is "API" for kotlin dsl?

How I can write this code in kotlin dsl? dependencies{ api'org.slf4j:slf4j-api:1.7.25' } I can't find for what I need to change groovy "api" (in dependencies block) in kotlin dsl. For example I want to use org.slf4j, I want to declare it like…
livkonrol
  • 13
  • 4
1
vote
1 answer

Use FlatDir in Gradle DependencyResolutionManagement

I wanted to use a local dependency (a jar file) relative to my root project directory in my main module as a buildscript classpath via dependencyResolutionManagement in settings.gradle.kts. Here's my settings.gradle.kts file: pluginManagement { …
You Qi
  • 8,353
  • 8
  • 50
  • 68
1
vote
1 answer

gradle kotlindsl extract logic to outer scripts

What is the recommended way to extract gradle build code blocks to external scripts? Notice these scripts should support references to the gradle project, extra etc. So - compiling kt files in buildSrc isn't what I'm looking for. I've tried to…
YaOg
  • 1,748
  • 5
  • 24
  • 43
1
vote
1 answer

Android Studio: adding build.gradle.kts (Kotlin DSL script) while creating new module

Recently I've migrated all my build scripts to Kotlin DSL. When I'm adding a new module in Android Studio I've got autogenerated build script written in Groovy. How can I update Android Studio new module template to use autogenerated build script…
Taxist Samael
  • 1,157
  • 1
  • 9
  • 23
1
vote
0 answers

How to apply plugin id("com.android.application") in build.gradle.kts?

This is my application code to add the plugin to Build.gradle.kts import java.io.ByteArrayOutputStream import java.text.SimpleDateFormat import java.util.Date import org.gradle.api.tasks.testing.logging.TestExceptionFormat …
1
vote
1 answer

How to assign value to kotlin variable from script step of TeamCity kotlin DSL?

I have several script steps in Kotlin DSL for TeamCity. For example here I update the parameter that was changed in previous buildTypes. script { scriptContent = """ TEMP_VAR=${'$'}(curl --insecure -v --Header "Content-Type:…
1
vote
1 answer

Which kotlin language feature is this

I'm learning about the kotlin DSL, specifically with Teamcity and I see an initialization pattern I don't really understand yet Kotlin playgound link Here is the code package org.arhan.kotlin fun main() { val project = project { …
ceiling cat
  • 496
  • 4
  • 12
1
vote
1 answer

Infix function in Kotlin DSL does not work without this keyword in parent context

I am writing a sample DSL to create an infra-as-code library. The basic structure would be as below: class Employee internal constructor (private val init: Employee.() -> Unit) { var name:String = "" var address:String = "" infix fun…
Dharmvir Tiwari
  • 886
  • 3
  • 12
  • 25