DEV Community

Dussim
Dussim

Posted on

3 4

Gradle precompiled script with kotlin("jvm")

My recent problems

So going right into details, recently I wanted to learn a bit of gradle and create precompiled script plugin for my kotlin modules to share dependencies, jvmTarget, repositories, plugins etc.
I tried to add folowing block to script:

plugins {
    kotlin("jvm") version "1.5.0"
}

dependencies {
    kapt(/*some dependency*/)
}

tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "13"
}

// other things
Enter fullscreen mode Exit fullscreen mode

And I was greeted with following message

Plugin requests from precompiled scripts must not include a version number. Please remove the version from the offending request and make sure the module containing the requested plugin 'org.jetbrains.kotlin.jvm' is an implementation dependency of project ':buildSrc'.
Enter fullscreen mode Exit fullscreen mode

It is obvious what should be done, isn't it?
It wasn't for me unfortunately.

Solution to the problem

I tried many things and googled a lot and I finally figured it out. Maybe this will be useful for anyone else.

// buildSrc/src/main/kotlin/kotlin-common.gradle.kts
plugins {
    kotlin("jvm")
}
// buildSrc/build.gradle.kts
plugins {
    `kotlin-dsl`
}

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0") // <---- This is our `kotlin("jvm")` plugin
}

repositories {
    mavenCentral()
}
Enter fullscreen mode Exit fullscreen mode

Respository with simple example

You can check out this repository for file structure and simple working example.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (1)

Collapse
 
lintong profile image
Linton Galloway

Thanks for this, works for me!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more