1

In my Android/Gradle project in the buildSrc folder I like to provide a property which returns the data type org.jetbrains.kotlin.gradle.dsl.JvmTarget in the buildSrc folder. The build configuration for this folder currently looks like this:

plugins {
    `kotlin-dsl`
}

repositories {
    mavenCentral()
}

Which plugin/dependency do I have to add to get access to org.jetbrains.kotlin.gradle.dsl data types?

1 Answer 1

1

To access org.jetbrains.kotlin.gradle.dsl.JvmTarget and other types related to the Kotlin plugin in normal Kotlin files (including Kotlin files in the buildSrc project), you should add the Kotlin Gradle plugin JAR to the classpath:

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22") 
}

Note that doing this in the buildSrc build.gradle.kts file adds the Kotlin plugin to the classpath of all build.gradle.kts files in the project, which means you will need to remove references to the version to other applications of the Kotlin plugin elsewhere in the build to avoid a Gradle error.

This also means that the version you specify in such a way in a buildSrc project will define the Kotlin plugin version throughout your project.

Sign up to request clarification or add additional context in comments.

8 Comments

I like to expose the property from a Kotlin file as drafted here. There the dependency cannot be resolved, though.
Ah, ok. I had misinterpreted your question. Now changed to cover regular Kotlin files.
Thank you for the rewrite. Adding the dependency to the project results in the following error: Failed to apply plugin 'kotlin-android'. Could not create an instance of type org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget. Removing other org.jetbrains.kotlin references doesn't help.
Classloader issues probably. I would put plugins { id("kotlin-android") apply false } in the root build.gradle file
I am still using the classpath and apply plugin syntax in my project. I could not find out how to use apply false in that setup.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.