This project contains a set of Gradle plugins to customize the standard build conventions to the ones used at LEOMO, Inc.
- Gradle 2.13 - 5.6.4
- Android plugin 3.6.0
In order to take advantage of the latest versions of Gradle and Android, see updating.md.
Remember that both group and version MUST be specified BEFORE
applying the Main Plugin.
I do suggest to keep them in the gradle.properties file alongside the build
itself.
This is especially evident when applying plugins with the new plugin loading
mechanism, where plugins must come before group or version
plugins {
id 'de.lemona.gradle' version '0.0.1'
}
// Wrong! Specified after the plugin is applied
group 'de.lemona.myproject'
version '1.2'
apply plugin: 'de.lemona.gradle'This is the master of all evils plugin. It will basically configure almost
anything else depending on the other plugins configured in your build.gradle
file.
This plugin will:
- Read the
~/.lemonade.propertiesfile (if present) and inject all properties as extra project properties.Note: any property specified on the command line as
-Pname=valuewill be left untouched. - Read the
lemonade.propertiesrelative to the current project (and to the current project's root project) and inject all properties as extra project properties.Note: any property specified on the command line as
-Pname=valueor in the user's~/.lemonade.propertiesread by the step above file will be left untouched. - Initialize the project's
versionfiled following Lemonade's versioning convertions - Set up repositories for dependency resolution:
- The Maven Central repository.
- Google's Maven repository.
- Set up the rest of our plugins:
- Add the Android Plugin if either the
com.android.applicationorcom.android.libraryplugins were specified in the build file. - Add the Publishing Plugin if the
maven-publishplugin was specified in the build file. - Add the S3 Repository Plugin if the project has
the
s3.repositoryproperty orS3_REPOSITORYenvironment variable.
Note: if you'd like to avoid using these libraries, set
leomo.enableAutoPluginApplyproperty (orLEOMO_ENABLE_AUTO_PLUGIN_APPLYenvironment variable) to false. Default true. - Add the Android Plugin if either the
The plugin will also inject a lemonade extension in the project containing
few utility methods:
requireValue(String propertyName, String envVariableName)- Resolve a property name or an environment variable, failing if either/or was not defined.
resolveValue(String propertyName, String envVariableName)- Resolve a property name or an environment variable, returning
nullif both were not defined.
- Resolve a property name or an environment variable, returning
resolveValue(String propertyName, String envVariableName, Object defaultValue)- Resolve a property name or an environment variable, returning the specified default value if both were not defined.
readProperties(Object fileName)- Read a properties file (relative to the project root) injecting the
properties as
extproperties to the current project.
- Read a properties file (relative to the project root) injecting the
properties as
apply plugin: 'de.lemona.gradle.android'This simple plugin will highlight test results in the console output (for
better integration with build systems) and create a javadoc task per each
build variant (debug, release, ...).
It will also simplify the generation of signingConfigs by adding a from
method in the plugin. For example:
signingConfigs {
from(debug, '../debugKeyStore.jks', 'debugKeyAlias')
from(release, '../releaseKeyStore.jks', 'releaseKeyAlias')
}The from(...) method will take three parameters:
- The configuration to sign (required)
- An optional keystore file (defaults to
keystore.jks) relative to the project root (if aString), or aFile. - An optional key alias (defaults to the configuration name) of the key alias in the key store to use.
Few properties and/or environment variables are needed for the configuration:
keystorePasswordproperty orKEYSTORE_PASSWORDenvironment variable- The password to decrypt the key store file
aliasNameKeyPasswordproperty orALIASNAME_KEY_PASSWORDenvironment variable- The password the key was encrypted with
In the example above, given the two debugKeyAlias and releaseKeyAlias
values, the properties searched will be debugKeyAliasKeyPassword and
releaseKeyAliasKeyPassword, while the environment variable names will be
DEBUGKEYALIAS_KEY_PASSWORD and RELEASEKEYALIAS_KEY_PASSWORD.
apply plugin: 'de.lemona.gradle.publishing'This plugin will publish Java and Android artifacts into a local Maven
repository under ${buildDir}/maven.
For Java artifacts the main java component, sources and javadoc jars will be published.
For Android libraries the aar file will be published.
For Android app an zip file which contains the apk file and the obfuscation mapping file.
The release variant will be published.
apply plugin: 'de.lemona.gradle.s3'This plugin requires three parameters:
s3.repositoryproperty orS3_REPOSITORYenvironment variable- Specifies the URL of the S3 maven repository
s3.accessKeyproperty orS3_ACCESS_KEYenvironment variable- Specifies the access key to be used to access the S3 repository
s3.secretKeyproperty orS3_SECRET_KEYenvironment variable- Specifies the secret key to be used to access the S3 repository
This plugin will allow dependencies to be resolved against an Amazon S3 backed Maven repository.
If the maven-publish plugin is also present, all publications will also
be uploaded to the same repository (using the same credentials).
In this case, use the uploadS3 task to actually perform the upload (the
publish task alone will only publish locally).
The original version must be a String in the major.minor format.
The Main Plugin will parse and overwrite gradle's version
field to be an object containing the following fields:
major: the major version number (from 0 to 127)minor: the minor version number (from 0 to 255)build: the build number (from 0 to 65533) or-1if this is a snapshotversionCode: the version code (calculated as a 32-bit integer frommajor,minorandbuild) for release or1for snapshot buildsisSnapshot: a flag indicating a release or snapshot build
The final toString() representation of the version will be either
minor.major.build or minor.major-SNAPSHOT
The versionCode will always be 1 for all snapshot builds. In case of a
release build, it will be a 32-bit signed positive number containing:
| Bit 0 ... 7 | Bit 8 ... 15 | Bit 16 ... 31 |
|---|---|---|
major version |
minor version |
build plus 2 |
Henceforth, version 0.0.0 will have versionCode=2 while version 1.2.3
will have versionCode=16908293 (or in hex 0x01020005).
Builds are always considered to be snapshot builds unless the buildNumber
property or the BUILD_NUMBER environment variables are specified.
Simply get the API keys after logging in on the Gradle Plugins website then:
$ gradle -PbuildNumber=... \
-Pgradle.publish.key=... \
-Pgradle.publish.secret=...
clean publishPlugins