Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to use kotlin-dsl in precompiled script plugins #17016

Open
vlsi opened this issue Apr 28, 2021 · 7 comments
Open

Provide a way to use kotlin-dsl in precompiled script plugins #17016

vlsi opened this issue Apr 28, 2021 · 7 comments

Comments

@vlsi
Copy link
Contributor

vlsi commented Apr 28, 2021

Expected Behavior

There should be a way to use kotlin-dsl for precompiled script plugins in idiomatic-gradle approach.

Current Behavior

I try using precompiled script plugins to factor the build logic.
In the build itself, I need kotlin-dsl plugin (so I do not apply kotlin-dsl everywhere, and I want an uber-plugin to apply it along with other plugins)

Of course, precompiled script plugins forbid versions, so I have the following for Gradle 6.8.3:

dependencies {
  implementation("org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:1.4.9")

Unfortunately, it breaks for Gradle 7 as follows:

> Configure project :
This version of Gradle expects version '2.1.4' of the `kotlin-dsl` plugin but version '1.4.9' has been applied to root project 'allure-gradle-sandbox'. Let Gradle control the version of `kotlin-dsl` by removing any explicit `kotlin-dsl` version constraints from your build logic.
WARNING: Unsupported Kotlin plugin version.
The `embedded-kotlin` and `kotlin-dsl` plugins rely on features of Kotlin `1.4.31` that might work differently than in the requested version `1.4.20`.
kotlin-dsl verison is 2.1.4

Note: if I completely remove the version of org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin dependency, then Gradle can't find the version. If I leave an old version, Gradle complains that it wants a specific one.

Context

I cannot use a project that uses Gradle 6.8 (e.g. Gradle plugin project) as an includedBuild in project that uses Gradle 7 since Gradle 7 wants every version to be "new and shiny", so it requests "removing any explicit kotlin-dsl version constraints", however it is not clear how it should be done.

@vlsi vlsi added a:feature A new functionality to-triage labels Apr 28, 2021
@vlsi
Copy link
Contributor Author

vlsi commented Apr 28, 2021

Currently I use the following workaround to fetch kotlin-dsl version 🤯

val kotlinDslVersion = PluginDependenciesSpec { id ->
    object : PluginDependencySpec {
        var version: String? = null
        override fun version(version: String?) = apply { this.version = version }
        override fun apply(apply: Boolean) = this
        override fun toString() = version ?: ""
    }
}.`kotlin-dsl`.toString()

@jjohannes
Copy link
Contributor

This is definitely an issue. It should be addressed as part of #15219.

@mochadwi
Copy link

this also happened for me in 6.8.3

@kikoso
Copy link

kikoso commented Nov 24, 2021

This does not seem to have been tackled yet. @jjohannes , do you have any update here?

@jjohannes
Copy link
Contributor

@kikoso sorry I am no longer in the Gradle team and I don't know what the timeline for this is.

I still think this should be addressed as it is a quite common issue that affects builds using a "modern" structuring approach for build logic.

@kikoso
Copy link

kikoso commented Dec 1, 2021

Thanks for the heads up @jjohannes !

@vlsi
Copy link
Contributor Author

vlsi commented Feb 6, 2023

I recently tried again, and I found org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion property, so the following works in Gradle 7.6:

import org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion

dependencies {
    implementation("org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:$expectedKotlinDslPluginsVersion")
}

It would still be nice to have something like

dependencies {
    implementation(kotlinDsl())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants