Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In gradle, how to use a variable for a plugin version?

One of my build scripts imports that nebula plugin:

plugins {   id 'nebula.ospackage' version '3.5.0' } 

I've been moving all of my version info into a separate file that all projects have access to and am wondering what is the correct syntax to convert to something like:

plugins {   id 'nebula.ospackage' version "$versions.nebula_gradle_ospackage_plugin" } 

When I try running the above with "gradle clean build", I get the following error:

build file 'build.gradle': 2: argument list must be exactly 1 literal non empty string

See https://docs.gradle.org/2.7/userguide/plugins.html#sec:plugins_block for information on the plugins {} block

@ line 2, column 33. id 'nebula.ospackage' version "$versions.nebula_gradle_ospackage_plugin"

The linked article shows how I could use the "buildscript" block, which works, but it seems like there must be a way to make this work in a single line?

like image 275
crobicha Avatar asked May 31 '16 20:05

crobicha


People also ask

How do I set the Gradle plugin version?

You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or update your Gradle version using the command line.

How do I find gradle plugin version?

In Android Studio, go to File > Project Structure. Then select the "project" tab on the left. Your Gradle version will be displayed here.

Which are the two types of plugins in gradle?

There are two general types of plugins in Gradle, binary plugins and script plugins.

What is apply plugin in gradle?

Applying a plugin to a project means that it allows the plugin to extend the project's capabilities. The plugins can do the things such as − Extend the basic Gradle model (e.g. add new DSL elements that can be configured).


2 Answers

You cannot use variable here:

Where «plugin version» and «plugin id» must be constant, literal, strings. No other statements are allowed; their presence will cause a compilation error.

like image 53
BoygeniusDexter Avatar answered Sep 20 '22 17:09

BoygeniusDexter


As of Gradle 5.6, you can declare your plugin versions in the gradle.properties file, and reference these properties in plugins block.

For example, the gradle.properties file:

springBootVersion=2.2.0.RELEASE 

the plugins block in build.gradle:

plugins {     id "org.springframework.boot" version "${springBootVersion}" } 

See: https://github.com/gradle/gradle/issues/1697#issuecomment-506910915.

See also:

  1. https://docs.gradle.org/5.6/release-notes.html#central-management-of-plugin-versions-with-settings-script
  2. https://docs.gradle.org/5.6/userguide/plugins.html#sec:plugin_management
like image 40
zhouji Avatar answered Sep 21 '22 17:09

zhouji