How to build, iterate and publish the plugin
Process flow
The process flow is as follows:
Ensure that you have built the scaffolding:
java -jar gradle-plugin-java-create-<version>.jar
- Edit the code to get it to do what you want it to do
- If you have never built the version of the plugin before
gradle -b build.plugin.initial.gradle build pTML
- Run and test the plugin
gradle -b build.plugin.gradle <taskName>
- Happy with the results
- Publish your plugin
build -b build.plugin.gradle build pP
- Publish your plugin
- Unhappy with the results?
- Update the version number in
build.plugin.initial.gradle
andbuild.plugin.gradle
- go back to the beginning
- Update the version number in
See below for more detailed instructions
The initial build
Step 1
Generate the scaffolding:
java -jar gradle-plugin-java-create-<version>.jar \
-a synapticloop \
-d "a simple test plugin" \
-dg Sample \
-dn "Synapticloop sample test plugin" \
-jp synapticloop.plugin.sample \
-n TestSample \
-t "test,sample"
Step 2
Check the following files to ensure that everything looks good to go: (Especially the version numbers which should default to 0.0.1
)
build.plugin.initial.gradle
- Ensure that the line
synapticloop(MavenPublication) {
is only a single word (i.e. it show heresynapticloop
and should not showcom.synapticloop
)
- Ensure that the line
build.plugin.gradle
Step 3
Build the initial plugin and publish it to maven local repository:
gradle -b build.plugin.initial.gradle build publishToMavenLocal
or as a shorcut:
gradle -b build.plugin.initial.gradle build pTML
Step 4
Test that the plugin is registered
gradle -b build.plugin.gradle tasks
You should see the following output:
... snip ...
Sample tasks
------------
testSample - a simple test plugin
... snip ...
Step 5
Run the plugin
gradle -b build.plugin.gradle testSample
And you will see the following output
:testSample
This will be logged as output on standard out.
Logging out the boolean value of 'booleanValue' as 'true'
Logging out the string value of 'stringValue' as 'this is a string value set from the build.plugin.gradle file'
Logging out the string value from the list 'stringList' as 'one'
Logging out the string value from the list 'stringList' as 'two'
Logging out the string value from the list 'stringList' as 'three'
BUILD SUCCESSFUL
Note that you do not see the 'info' or 'debug' messages - to see these, you will need to pass in the --info
, or --debug
command line parameters to the gradle build.
Iterating
Now that you have tested that the build works, you can now iterate over the Task.java
code until it works as expected.
Updating the plugin version
In the build.plugin.initial.gradle
file, update the version number in the line version = '0.0.1'
and then:
gradle -b build.plugin.initial.gradle build pTML
This will publish the plugin to the local maven repository which you can then update the plugin number in the build.plugin.gradle
file and test it again.
Publishing
Now that you have iterated and built the plugin - and you are happy with your plugin, you need to publish it.
Step 1
Login or signup to the gradle plugin portal ensuring that you have specified your username.
Step 2
Retrieve your API keys buy clinking on the 'API Keys' tab on your home page. Follow the instructions (i.e. copy the gradle.publish.key
and gradle.publish.secret
) to your gradle.properties
file (e.g. HOME_DIR/.gradle/gradle.properties
).
gradle -b build.plugin.gradle build publishPlugin
or just simply
gradle -b build.plugin.gradle build pP
Step 3
You, (and everybody else) is now ready to use your plugin - congratulations!