Gradle: how to use the latest version of a plugin automatically
Asked Answered
J

3

6

I have developed an internal plugin. The plugin has its own version. I then use that plugin for a build process in a repository. If I change the version of the plugin, I have to update the build.gradle to spell our the new version. I have about 100 of these repositories. Is there a way to specify in my build.gradle to use the latest version of the plugin that can be found in that location? I could ran a batch file before gradle that find the latest, updates build.gradle with that number and then runs the build process but this is a big work around to a functionality that should be available. See code below where I call the plugin that I change quite often:

    buildscript {
    repositories {
        maven {
            url "c:/git/_TEST/plug-in"
        }
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath group: 'com.myplugin.gradle', name: 'com.myplugin.mypluginbuild', version: '1.0'
    }
apply plugin: 'com.myplugin.mypluginbuild'
}

if I don't specify the version, it returns an error. Any suggestions?

Jot answered 15/2, 2017 at 20:26 Comment(2)
You can use dynamic versions: docs.gradle.org/current/userguide/…Thora
No, they don't seem to work for community plugins: [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Plugin [id: 'com.dorongold.task-tree', version: '1.3+'] was not found in any of the following sources: 10:25:24.593 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 10:25:24.593 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] - Gradle Core Plugins (plugin is not in 'org.gradle' namespace) 10:25:24.593 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] - Plugin Repositories (dynamic plugin versions are not supported)Zeller
R
4

For those who use plugins{} block, gradle7+ supports dynamic version, which includes + and latest.release.

plugins {
    id "your-plugin-id" version "1.0.+"
}

dynamic version doc

Rhombohedron answered 5/7, 2021 at 12:6 Comment(0)
S
2

It's not possible this way. See the plugins {} block and plugins documentation.

  • For core plugins you must not provide a version.
  • For community plugins you have to provide a version.

Maybe script plugins are way to go:

apply from: 'my_script_plugin.gradle'
Signore answered 15/2, 2017 at 20:42 Comment(1)
Good suggestion but I am not able to use the Id statement. It fails because it can't find "com.myplugin.mypluginbuild" in Gradle Core or Gradle Central Repository. How do I implement it?Jot
J
0

I have a solution to this question. The + specified in the version field will do the trick. It will enable gradle to use the latest plug-in automatically. I.e:

dependencies {
        classpath group: 'com.myplugin.gradle', name: 'com.myplugin.mypluginbuild', version: '1.+'
    }
Jot answered 21/2, 2017 at 15:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.