Plugin.java

The plugin file TestSamplePlugin.java file is output to the ./src/main/java/synapticloop/plugin/sample directory. This is the object that registers the plugin extension and the plugin task into the project.

Looking at the file, you will see the contents:

package synapticloop.plugin.sample;

// - - - - thoughtfully generated by synapticloop gradle-plugin-java-create - - - - 
//             with the use of synapticloop templar templating language
//                           (plugin.java.templar)


import org.gradle.api.Plugin;
import org.gradle.api.Project;

public class TestSamplePlugin implements Plugin {
	public static final String PLUGIN_NAME = "testSample";

	@Override
	public void apply(Project project) {
		// Register the plugin extension with the project
		project.getExtensions().create(PLUGIN_NAME, TestSamplePluginExtension.class);

		// Register the plugin task with the project
		project.getTasks().create(PLUGIN_NAME, TestSampleTask.class);
	}
}

Variables used in the generation

TestSamplePlugin.java uses the following variables:

  • {package} - the command line argument -p or --package
    • This is split on the '.' character to create the output directory structure.
    • This becomes the package {package}; declaration at the top of the file
  • {name} - the command line argument -n or --name
    • This becomes the file name {name}Plugin.java
    • This becomes the class declaration public class {name}Plugin implements Plugin {
  • {lowerName} - this is generated from the -n or --name command line argument. NOTE: this isgenerated from the {name} variable with its first letter lowercased. (e.g. TestSample -> testSample)
    • This is used to create the plugin extensions for the build.gradle file: public static final String PLUGIN_NAME = "{lowerName}";

Things of note

You probably won't need to change anything in this file, however, a few things to note:

  1. If you want to add additional tasks and extensions, this is the place to add them. You may have as many tasks as you require - optionally with additional extensions for each task. Alternatively you may only have one extension which can service all of the tasks.
  2. The name of the file is important - this must match the fully qualified class name that is referenced in the .properties file (in this case the synapticloop.plugin.sample.TestSample.properties file)