Related to How to get $ project.version in a custom Gradle plugin?
Summary: getVersion () inside a custom Gradle plugin returns "unspecified"
I created a custom Gradle plugin that applies some business logic to our Android Studio / Gradle builds. This plugin is launched every time we build CI.
I want the plugin to be able to print its version, which is a completely different version number from the version of the Android application that is created during the build. (useful debugging information during CI build)
The build.gradle plugin for the plugin (which is deployed to the maven repository as a jar):
buildscript { repositories { mavenCentral() } } apply plugin: 'groovy' apply plugin: 'maven' group = 'com.example.foo.gradle' version = "0.0.12" sourceCompatibility = JavaVersion.VERSION_1_6 targetCompatibility = JavaVersion.VERSION_1_6 dependencies { repositories { mavenCentral() } compile gradleApi() compile localGroovy() } configurations { includeInJar } dependencies { //testCompile 'junit:junit:4.11' } jar { } uploadArchives { repositories.mavenDeployer { def deployPath = file(getProperty('aar.deployPath')) repository(url: "file://${deployPath.absolutePath}") pom.project { groupId project.group artifactId 'foo-gradle-jenkins' version project.version } } }
... and the plugin is applied to an Android application like this (sensitive parts are omitted):
buildscript { repositories { mavenCentral() maven { url "../../../plugin_builds" } } dependencies { classpath 'com.example.foo.gradle:foo-gradle-jenkins:0.0.+' } } apply plugin: 'com.android.application' apply plugin: 'foo' android { compileSdkVersion 20 buildToolsVersion "20.0.0" defaultConfig { applicationId "com.example.android.examplegradleapplication3" minSdkVersion 14 targetSdkVersion 20 versionCode 1 versionName "1.0" } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) }
In the plugin, I am trying to print my version as follows:
@Override void apply(Project project) { project.configure(project) { if (it.hasProperty("android")) { if (isJenkinsBuild()) { log("Plugin version: " + getVersion())
.. but whenever I build Gradle build an Android app, it thinks getVersion () is not specified.
What should I do instead to keep track of the plugin version during another Gradle build, using it as a plugin?
Npike
source share