javagradleantkeystorekey-generator

Generate keys in gradle


Currently I'm using ant XML to generate keys and sign jars.

I would like to eliminate the XML in the future by converting everything into a Gradle task without using ant.importBuild and not having to manually create keys with keytool -genkey. I believe I have the signing part figured out but need help with the key generation in gradle.

In the ant XML it currently looks like this:

<genkey alias="${key.alias}" keystore="${keystore.location}" storepass="${keystore.password}" dname="CN=name, OU=IT, O=org, C=US"/>

Is there an equivalent task to generate keys built into gradle? Unless I'm missing something Gradle seems to always assume the keys have already been generated.

I've read these ant and signing plugin pages but perhaps I can't see the forest because I'm lost in the trees.

Thank you.


Solution

  • Gradle treats Ant as a 'First Class Citizen'.

    You can invoke any common Ant task in Gradle simply by prefixing the task name with ant. Properties are set similar to parameters to a method call. For more information see this link: https://docs.gradle.org/current/userguide/ant.html

    So, for your case it would look something like:

    ant.genkey(alias:$keyAlias, keystore:$keystoreLocation, storepass:$storePass, dname:'$dName)