#How can I dynamically change a plugin's version depending on certain criteria?

8 messages · Page 1 of 1 (latest)

naive yew
#

We have a multi platform project, however each platform has its own platform-dependent implementation of some classes. In our case, 2 of these target platforms require the same plugin, however they rely on different versions.

So far, I have tried to dynamically set extra[pluginVersion] via either -PbuildingForB and gradle.taskGraph.whenReady , then setting a classpath in the dependencies block of the buildscript block, and finally applying the plugin after the plugins block. Unfortunately, this errors with Cannot get property 'pluginVersion' on extra properties extension as it does not exist.

buildscript {
  extra {
    "pluginVersionA" to "1.0"
    "pluginVersionB" to "2.0"
    "pluginVersion" to "1.0"
  }

  extra["pluginVersion"] = project.findProperty("buildingForB")?.let {
        if (it == "true") extra["pluginVersionB"] else extra["pluginVersionA"]
  } ?: extra["pluginVersionA"]

  gradle.taskGraph.whenReady {
    if (tasks.contains(task("buildPlatformB")))
      extra["pluginVersion"] = extra["pluginVersionB"];
  }

  repositories {
    mavenCentral()
  }
  dependencies {
    classpath("com.example:example-plugin:${extra["pluginVersion"]}")
  }
}

plugins {
  ...
}

apply(plugin = "org.example")
balmy tundraBOT
#

This post has been reserved for your question.

Hey @naive yew! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

naive yew
#

How can I dynamically change a plugin's version depending on certain critera?

#

How can I dynamically change a plugin's version depending on certain criteria?

muted gate
#

Why are you using extra as opposed to just defining a variable?

naive yew
#

using this

val versionA = "1.0"
val versionB = "2.0"
var pluginVersion = versionA

pluginVersion = project.findProperty("buildingForB")?.let {
  if (it == "true") versionB else versionA
} ?: versionA

gradle.taskGraph.whenReady {
  if (tasks.contains(task("buildPlatformB")))
    pluginVersion = versionB
}

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath("com.example:example-plugin:${pluginVersion]}")
  }
}

apply(plugin = "com.example")

errors with Unresolved reference: pluginVersion