5.8 Archetypes

While it's true that artifact templates can be provided by plugins it simply was not possible to configure how an application is created. Application Archetypes fill this gap by providing a hook into the application creation process. Archetypes can do the following:

- provide new versions of existing templates, like Model, Controller and so forth
- create new directories and files
- most importantly perhaps, install a preset of plugins

So, if your company requires all applications to be built following the same template and basic behavior then you can create an archetype that enforces those constraints. Archetypes are simple zip files with an application descriptor and templates. Despite this, Griffon provides a few scripts that let you manage archetypes

- create-archetype
- package-archetype
- install-archetype
- uninstall-archetype

Archetypes are installed per Griffon location under `$USER_HOME/.griffon/<version>/archetypes`. Archetypes are registered with an application's metadata when creating an application. You can either manually modify the value of 'app.archetype' to a known archetype name or specify an `-archetype=<archetypeName>` flag when creating a new application.

If no valid archetype is found then the default archetype will be used. Following is the default template for an application archetype

    import griffon.util.MetadataincludeTargets << griffonScript('CreateMvc')target(name: 'createApplicationProject',
            description: 'Creates a new application project',
            prehook: null, posthook: null) {
        createProjectWithDefaults()
        createMVC()    // to install plugins do the following
        // Metadata md = Metadata.getInstance(new File("${basedir}/application.properties"))
        //
        // for a single plugin
        //     installPluginExternal md, pluginName, pluginVersion
        //        ** pluginVersion is optional **
        //
        // for multiple plugins where the latest version is preferred
        //     installPluginsLatest md, [pluginName1, pluginName2]
        //
        // for multiple plugins with an specific version
        //     installPlugins md, [pluginName1: pluginVersion1]
    }
    setDefaultTarget(createApplicationProject)