Class CreatePom
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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDevelopers
(Developers developers) Allows ant to add aDevelopers
section.void
addLicenses
(Licenses licenses) Add a licenses element to the POM.void
addRepositories
(Repositories repositories) Add a repositories element to the POM.void
Allows ant to add aScm
section.void
execute()
Execute the task to create the POM file.Get the artifactId.Get the description.Get the groupId.getName()
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
-
Constructor Details
-
CreatePom
public CreatePom()Default constructor.
-
-
Method Details
-
setPomTarget
The path to the file that the POM content should be written to.- Parameters:
pomTarget
- the target file for the POM
-
setPomTarget
The path to the file that the POM content should be written to.- Parameters:
pomTarget
- the target file for the POM
-
setDependencyManagementRef
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
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
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
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
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
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
Get the description for the POM.- Returns:
- the description for the POM
-
setDescription
Set the description for the POM. The description can include properties that will be replaced at runtime.- Overrides:
setDescription
in classorg.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
Default is false, meaning the POM will be registered.<pom file="${pomFile}"/>
- Parameters:
skipPomRegistration
- true to skip registration, false to register the POM
-
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
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
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
Get the description. If the description is not set, it will return a default value based on the project property 'description'.- Overrides:
getDescription
in classorg.apache.tools.ant.ProjectComponent
- Returns:
- the description for the POM
-
addLicenses
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
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
Allows ant to add aDevelopers
section.- Parameters:
developers
- theDevelopers
to add
-
addScm
Allows ant to add aScm
section.- Parameters:
scm
- theScm
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 classorg.apache.tools.ant.Task
-