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

Move plugin version management to buildSrc/build.gradle.kts #1321

Closed
wants to merge 1 commit into from

Conversation

floscher
Copy link

While researching a similar issue, I recently came across gradle/gradle#11090 (comment) (cc @sellmair ) about how the pluginManagement{} block in settings.gradle.kts can't access logic defined in buildSrc.

So I thought I'd share how I'm trying to solve that problem in some of my projects. Just in case this could be useful for this project, too.

There are two parts to this solution:


There is a second buildSrc project inside the existing buildSrc project. It only contains a short build.gradle.kts script and just compiles the sources of the first buildSrc project one additional time, so those classes are on the classpath of buildSrc/build.gradle.kts.

At the moment this is not utilized in this pull request, but you could then add build logic to buildSrc/src/main/kotlin that can be reused in the buildscript of buildSrc for e.g. plugin version management.

This may sound like a hack, but in my experience this works pretty reliably.


The plugin versions are defined in buildSrc/build.gradle.kts as dependencies.implementation("‹…›") instead of using the pluginManagement{} block in settings.gradle.kts.

This gets rid of version inconsistencies like

id("com.jfrog.bintray") version "1.8.5"
vs
implementation("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4")
Both are now defined in one location.

Also subprojects can then no longer declare conflicting plugin versions like

id("com.gradle.plugin-publish") version "0.12.0"
and
id("com.gradle.plugin-publish") version "0.10.1"
because Gradle will issue a warning: Plugin request for plugin already on the classpath must not include a version.

Comment on lines +17 to 37
repositories {
exclusiveContent {
forRepository {
gradlePluginPortal()
}
filter {
pluginVersions.forEach { includeVersion(it.group!!, it.name, it.version!!) }
}
}
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap/") {
content {
includeGroupByRegex("^org\\.jetbrains\\.(anko|dokka|kotlin|kotlinx)(\\..+)?$")
}
}
maven("https://dl.bintray.com/kotlin/kotlin-dev/") {
content {
includeGroupByRegex("^org\\.jetbrains\\.(anko|dokka|intellij|kotlin|kotlinx)(\\..+)?$")
}
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I added an exclusiveContent rule for the plugins to only be taken from gradlePluginPortal() and some regex rules for kotlin-eap and kotlin-dev to avoid unnecessary requests to those repos.

This could be replaced by some more elaborate logic in buildSrc/src/main/kotlin that could then be reused in any other Gradle buildscript in the project (except buildSrc/buildSrc/build.gradle.kts).

@sellmair sellmair added enhancement An issue for a feature or an overall improvement infrastructure Everything related to builds tools, CI configurations and project tooling labels Aug 17, 2020
@sellmair sellmair self-requested a review August 17, 2020 12:56
@sellmair sellmair self-assigned this Aug 17, 2020
@sellmair sellmair added this to the 1.4.10 milestone Aug 17, 2020
@vmishenev vmishenev force-pushed the master branch 2 times, most recently from de135ce to 4397c96 Compare December 7, 2021 17:10
@yalishevant yalishevant added the runner: Gradle plugin An issue/PR related to Dokka's Gradle plugin label Apr 5, 2022
@yalishevant yalishevant modified the milestones: Backlog, Stable Apr 5, 2022
@yalishevant yalishevant modified the milestones: Stable, Backlog Nov 7, 2022
@IgnatBeresnev
Copy link
Member

Thank you for the effort! Sorry it hasn't been addressed properly.

I'll close this PR in favour of #2704, there's quite a bit of refactoring, including the move of plugin version management to buildSrc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An issue for a feature or an overall improvement infrastructure Everything related to builds tools, CI configurations and project tooling runner: Gradle plugin An issue/PR related to Dokka's Gradle plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants