Package: org.codehaus.groovy.grails.cli.maven

## [Groovy] Class MavenPomGenerator

- org.codehaus.groovy.grails.cli.maven.MavenPomGenerator

- Generates a POM for a Grails application.

  Authors:
    Graeme Rocher
    Peter Ledbrook
  Since:
    2.1

- - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class BaseSettingsApi` | `appClassName, buildEventListener, buildProps, buildSettings, configSlurper, enableProfile, grailsAppName, grailsHome, isInteractive, metadata, metadataFile, pluginSettings, pluginsHome, resolver`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `MavenPomGenerator (BuildSettings buildSettings)`

  - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `protected java.util.List<DependencyInfo>` | `convertExclusionsToRealDeps(Dependency dependency)` Converts the exclusions of a dependency into real, resolved dependencies.
    `protected java.util.Map` | `createModel(java.lang.String group, java.io.File projDir)` Creates a standard template model based on the target directory containing a Grails project.
    `protected java.util.Map` | `createModel(java.lang.String group, Metadata projInfo, GrailsPluginInfo pluginInfo = null)`
    `void` | `generate(java.lang.String group)` Creates a `pom.xml` file for the current Grails project, i.e. the one pointed to by the build's base directory.
    `DependencyInfo` | `generate(java.lang.String group, java.io.File projDir, java.util.Map addedModel)` Creates a `pom.xml` file for the Grails project in the given directory.
    `void` | `generatePom(java.io.File projDir, java.lang.String templatePath, java.util.Map model)` Creates a `pom.xml` file in the target directory using the template located at the given path combined with the given model.
    `void` | `generateWithParent(java.lang.String group)` This does the same as generate(java.lang.String), but the generated POM includes a `parent` element containing the details of whatever POM is found in the current project's parent directory.
    `protected java.util.List<DependencyInfo>` | `getDependenciesForScope(DependencyManager dependencyManager, java.lang.String scope, java.lang.String type = "", java.lang.String newScope = null)` Returns a list of plugin or application dependencies stored in the given dependency manager.
    `protected java.util.Map` | `getParentModel(java.io.File pomFile)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class BaseSettingsApi` | `confirmInput, confirmInput, copyGrailsResource, copyGrailsResource, copyGrailsResources, copyGrailsResources, createXmlSlurper, enableUaa, exit, getAppClassName, getAppGrailsVersion, getBuildEventListener, getBuildProps, getBuildSettings, getConfigSlurper, getGrailsAppName, getGrailsAppVersion, getGrailsHome, getIsInteractive, getMetadata, getMetadataFile, getPluginBuildSettings, getPluginSettings, getPluginsHome, getPropertyValue, getResolver, getServerHost, getServerPort, getServerPortHttps, getServletVersion, grailsResource, isDeclared, isEnableProfile, logError, logErrorAndExit, makeApiAvailableToScripts, makeRelative, makeRelative, profile, readAllPluginXmlMetadata, readPluginXmlMetadata, resolveResources, updateMetadata, updateMetadata`
    `class java.lang.Object` | `java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Constructor Detail

    - #### MavenPomGenerator(BuildSettings buildSettings)

  - ### Method Detail

    - #### protected java.util.List<DependencyInfo> convertExclusionsToRealDeps(Dependency dependency)

      Converts the exclusions of a dependency into real, resolved dependencies. This is to account for the fact that Ivy allows for exclusions based on group or name alone. Maven requires both the group and name for exclusion. Therefore, this method resolves the current dependency and looks for matching transitive dependencies that are to be excluded from the current dependency in the generated POM file.

      Parameters:
        `dependency` - The current dependency that may have exclusions.
      Returns:
        The list of actually excluded transitive dependencies or an empty list if there are no excluded dependencies.

    - #### protected java.util.Map createModel(java.lang.String group, java.io.File projDir)

      Creates a standard template model based on the target directory containing a Grails project. The method will pick out the project's name, version, and dependencies from the appropriate files. It works for both application and plugin projects.

      Parameters:
        `group` - This is used to populate the model with the variable used for the POM's `groupId` element.
        `projDir` - The directory containing the Grails project of interest.
      Returns:
        A standard template model.

    - #### protected java.util.Map createModel(java.lang.String group, Metadata projInfo, GrailsPluginInfo pluginInfo = null)

    - #### void generate(java.lang.String group)

      Creates a `pom.xml` file for the current Grails project, i.e. the one pointed to by the build's base directory. The generated POM will include the JAR and plugin dependencies declared in `BuildConfig.groovy`.

      Parameters:
        `group` - The string to use for the POM's `groupId` element.

    - #### DependencyInfo generate(java.lang.String group, java.io.File projDir, java.util.Map addedModel)

      Creates a `pom.xml` file for the Grails project in the given directory. It not only allows you to provide a value for the `groupId`, but you can also provide additional values for the POM template.

      Parameters:
        `group` - The string to use for the POM's `groupId` element.
        `projDir` - The directory containing the Grails project you want to create a POM for. It must exist!
        `addedModel` - A map of additional values for the template. Supported variables are:
        - parent - with `group`, `name` and `version` sub-keys
        - group - the `groupId` string
        - name - the `artifactId` string
        - packaging - the `packaging` string, e.g. 'zip'
        - version - the `versions` string
        - dependencies - a list of JAR DependencyInfo instances that will be merged with the ones derived from `BuildConfig.groovy`
        - plugins - a list of plugin DependencyInfo instances that will be merged with the ones derived from `BuildConfig.groovy`

    - #### void generatePom(java.io.File projDir, java.lang.String templatePath, java.util.Map model)

      Creates a `pom.xml` file in the target directory using the template located at the given path combined with the given model. The template path is resolved as a Grails resource (which may be in the grails-resources JAR or in `$GRAILS_HOME` on the filesystem).

      Parameters:
        `projDir` - The target directory to put the POM.
        `templatePath` - A relative Grails resource path to the template file to use. The template must conform to Groovy's `SimpleTemplateEngine` syntax.
        `model` - A map of variables and values that will be substituted into the template.

    - #### void generateWithParent(java.lang.String group)

      This does the same as generate(java.lang.String), but the generated POM includes a `parent` element containing the details of whatever POM is found in the current project's parent directory. The current project is defined as the one in the build's base directory.

      throws:
        FileNotFoundException if a POM cannot be found in the current project's parent directory.
      Parameters:
        `group` - The string to use for the POM's `groupId` element.

    - #### protected java.util.List<DependencyInfo> getDependenciesForScope(DependencyManager dependencyManager, java.lang.String scope, java.lang.String type = "", java.lang.String newScope = null)

      Returns a list of plugin or application dependencies stored in the given dependency manager.

      Parameters:
        `scope` - The dependency scope you're interested in, e.g. 'compile', 'provided', etc.
        `type` - The type of the dependencies you want. This can by `null` or an empty string, both of which imply you want just JAR dependencies. Any other type is assumed to mean you want the plugin dependencies. The returned DependencyInfo instances will use the type you specify here.
        `newScope` - If specified, the returned DependencyInfo instances will use this for the `scope` property. Otherwise, they will use the value from the `scope` argument.
      Returns:
        A list of DependencyInfo instances for either the resolved JAR dependencies or plugin dependencies.

    - #### protected java.util.Map getParentModel(java.io.File pomFile)