java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.maven.resolver.internal.ant.tasks.CreatePom
All Implemented Interfaces:
Cloneable

public class CreatePom extends org.apache.tools.ant.Task
Task to create a Maven POM file. This task allows you to define dependencies, dependency management, description, licenses, scm, and repositories for the POM. This is useful if you have defined your dependencies in the ant build script instead of in the POM. This task also registers the POM. Note: if you want to publish your open source library to maven central using the new central publisher api, the following 4 additional sections are required in the pom: description, licenses, developers, and scm.

Usage Example:


 <repo:createPom pomTarget='${pomFile}'
                 dependenciesRef='compile'
                 dependencyManagementRef='dm'
                 name='mylib'
                 description='An useful library'>
   <licenses>
     <license>
       <name>MIT</name>
       <url>https://opensource.org/license/mit</url>
     </license>
   </licenses>
   <developers>
     <developer>
       <id>pnyfelt</id>
       <name>Per Nyfelt</name>
     </developer>
   </developers>
  <scm>
    <url>https://github.com/pnyfelt/example3/tree/master</url>
    <connection>scm:git:https://github.com/pnyfelt/example3.git</connection>
    <developerConnection>scm:git:https://github.com/pnyfelt/example3.git</developerConnection>
  </scm>
 </repo:createPom>
 

Attributes:

  • dependenciesIdRef - (optional) The reference to the id of the <dependencies> section
  • dependencyManagementRef - (optional) The reference to the id of the <dependencyManagement> section
  • pomTarget - The path to the POM file to create
  • groupId - The group id for the artifact(s), if a groupId property is set this can be omitted
  • artifactId - The artifact id for the artifact(s), if an artifactId property is set this can be omitted
  • version - The version for the artifact(s), if a version property is set this can be omitted
  • name - (optional) The name of the project
  • description - (optional) The short description of the project
  • skipPomRegistration - (optional) If set to true, the pom task will not be called to register the pom so must be done explicitly in the build script. Defaults to false.

Nested Elements:

  • <licenses> — (optional) specifies the licenses for the artifact.
  • <repositories> — (optional) defines the additional repositories used for resolving dependencies

Behavior:

  • groupId, artifactId and version are required. They could either be defined as properties or passed as attributes to the createPom task.
  • Field Summary

    Fields inherited from class org.apache.tools.ant.Task

    target, taskName, taskType, wrapper

    Fields inherited from class org.apache.tools.ant.ProjectComponent

    location, project
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Allows ant to add a Developers section.
    void
    Add a licenses element to the POM.
    void
    Add a repositories element to the POM.
    void
    addScm(Scm scm)
    Allows ant to add a Scm section.
    void
    Execute the task to create the POM file.
    Get the artifactId.
    Get the description.
    Get the groupId.
    Get the description for the POM.
    Get the version.
    void
    setArtifactId(String artifactId)
    Set the artifactId for the POM.
    void
    setDependenciesRef(String dependenciesIdReference)
    The reference to the dependencies section.
    void
    setDependencyManagementRef(String dependencyManagementRefId)
    The reference to the dependency management section.
    void
    setDescription(String description)
    Set the description for the POM.
    void
    setGroupId(String groupId)
    Set the groupId for the POM.
    void
    Set the name for the POM.
    void
    setPomTarget(File pomTarget)
    The path to the file that the POM content should be written to.
    void
    setPomTarget(String pomTarget)
    The path to the file that the POM content should be written to.
    void
    setSkipPomRegistration(boolean skipPomRegistration)
    skipPomRegistration is a flag to indicate whether the POM should be registered in the project after creation.
    void
    setVersion(String version)
    Set the version for the POM.

    Methods inherited from class org.apache.tools.ant.Task

    bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType

    Methods inherited from class org.apache.tools.ant.ProjectComponent

    clone, getLocation, getProject, setLocation, setProject

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CreatePom

      public CreatePom()
      Default constructor.
  • Method Details

    • setPomTarget

      public void setPomTarget(String pomTarget)
      The path to the file that the POM content should be written to.
      Parameters:
      pomTarget - the target file for the POM
    • setPomTarget

      public void setPomTarget(File pomTarget)
      The path to the file that the POM content should be written to.
      Parameters:
      pomTarget - the target file for the POM
    • setDependencyManagementRef

      public void setDependencyManagementRef(String dependencyManagementRefId)
      The reference to the dependency management section. This should point to the id attribute of a dependencyManagement element defined elsewhere in the build file.
      Parameters:
      dependencyManagementRefId - the reference to the id of the dependency management section
    • setDependenciesRef

      public void setDependenciesRef(String dependenciesIdReference)
      The reference to the dependencies section. This should point to the id attribute of a dependencies element defined elsewhere in the build file.
      Parameters:
      dependenciesIdReference - the reference to the id of the dependencies section
    • setGroupId

      public void setGroupId(String groupId)
      Set the groupId for the POM. The groupId can include properties that will be replaced at runtime.
      Parameters:
      groupId - the groupId for the POM
    • setArtifactId

      public void setArtifactId(String artifactId)
      Set the artifactId for the POM. The artifactId can include properties that will be replaced at runtime.
      Parameters:
      artifactId - the artifactId for the POM
    • setVersion

      public void setVersion(String version)
      Set the version for the POM. The version can include properties that will be replaced at runtime.
      Parameters:
      version - the version for the POM
    • setName

      public void setName(String name)
      Set the name for the POM. The name can include properties that will be replaced at runtime.
      Parameters:
      name - the name for the POM
    • getName

      public String getName()
      Get the description for the POM.
      Returns:
      the description for the POM
    • setDescription

      public void setDescription(String description)
      Set the description for the POM. The description can include properties that will be replaced at runtime.
      Overrides:
      setDescription in class org.apache.tools.ant.ProjectComponent
      Parameters:
      description - the description for the POM
    • setSkipPomRegistration

      public void setSkipPomRegistration(boolean skipPomRegistration)
      skipPomRegistration is a flag to indicate whether the POM should be registered in the project after creation. Setting this to false is equivalent to doing
      
         <pom file="${pomFile}"/>
       
      Default is false, meaning the POM will be registered.
      Parameters:
      skipPomRegistration - true to skip registration, false to register the POM
    • getGroupId

      public String getGroupId()
      Get the groupId. If the groupId is not set, it will return a default value based on the project property 'groupId'.
      Returns:
      the groupId for the POM
    • getArtifactId

      public String getArtifactId()
      Get the artifactId. If the artifactId is not set, it will return a default value based on the project property 'artifactId'.
      Returns:
      the artifactId for the POM
    • getVersion

      public String getVersion()
      Get the version. If the version is not set, it will return a default value based on the project property 'version'.
      Returns:
      the version for the POM
    • getDescription

      public String getDescription()
      Get the description. If the description is not set, it will return a default value based on the project property 'description'.
      Overrides:
      getDescription in class org.apache.tools.ant.ProjectComponent
      Returns:
      the description for the POM
    • addLicenses

      public void addLicenses(Licenses licenses)
      Add a licenses element to the POM. This allows you to specify one or more licenses that the project is distributed under.
      Parameters:
      licenses - the licenses to add to the POM
    • addRepositories

      public void addRepositories(Repositories repositories)
      Add a repositories element to the POM. This allows you to specify one or more repositories where dependencies can be found. Note that specifying repositories in the POM is discouraged if you aim to publish to maven central.
      Parameters:
      repositories - the repositories to add to the POM
    • addDevelopers

      public void addDevelopers(Developers developers)
      Allows ant to add a Developers section.
      Parameters:
      developers - the Developers to add
    • addScm

      public void addScm(Scm scm)
      Allows ant to add a Scm section.
      Parameters:
      scm - the Scm to add
    • execute

      public void execute()
      Execute the task to create the POM file. This method will create the POM file with the specified properties and dependencies.
      Overrides:
      execute in class org.apache.tools.ant.Task