Class AntRunMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.apache.maven.plugins.antrun.AntRunMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

@Mojo(name="run", threadSafe=true, requiresDependencyResolution=TEST) public class AntRunMojo extends org.apache.maven.plugin.AbstractMojo

Maven AntRun Mojo.

This plugin provides the capability of calling Ant tasks from a POM by running the nested Ant tasks inside the <target/> parameter. It is encouraged to move the actual tasks to a separate build.xml file and call that file with an <ant/> task.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The path to The XML file containing the definition of the Maven tasks.
    private String
    The xml tag prefix to use for the built in Ant tasks.
    static final String
    The default target name.
    static final String
    The refid used to store the Maven project object in the Ant build.
    static final String
    The refid used to store an object of type MavenAntRunProject containing the Maven project object in the Ant build.
    static final String
    The refid used to store the Maven project object in the Ant build.
    private boolean
    Specifies whether the Ant properties should be propagated to the Maven properties.
    private boolean
    Specifies whether a failure in the Ant build leads to a failure of the Maven build.
    protected org.apache.maven.artifact.repository.ArtifactRepository
    The local Maven repository
    static final String
    The prefix of all refid used by the plugin.
    private org.apache.maven.project.MavenProject
    The Maven project object
    private List<org.apache.maven.artifact.Artifact>
    The plugin dependencies.
    private org.apache.maven.project.MavenProjectHelper
    The Maven project helper object
    private String
    String to prepend to project and dependency property names.
    private org.apache.maven.execution.MavenSession
    The Maven session object
    private boolean
    Specifies whether the Antrun execution should be skipped.
    private File
    Deprecated.
    Use the build-helper-maven-plugin to bind source directories.
    private org.codehaus.plexus.configuration.PlexusConfiguration
    The XML for the Ant target.
    static final String
    The URI which defines the built in Ant tasks
    private org.codehaus.plexus.configuration.PlexusConfiguration
    Deprecated.
    Use target instead.
    private File
    Deprecated.
    Use the build-helper-maven-plugin to bind test source directories.
    static final String
    The default encoding to use for the generated Ant build.
    private String
    The name of a property containing the list of all dependency versions.

    Fields inherited from interface org.apache.maven.plugin.Mojo

    ROLE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    addAntProjectReferences(org.apache.maven.project.MavenProject mavenProject, org.apache.tools.ant.Project antProject)
     
    private void
    checkDeprecatedParameterUsage(Object parameter, String name, String replacement)
     
    void
    copyProperties(org.apache.maven.project.MavenProject mavenProject, org.apache.tools.ant.Project antProject)
    Copy properties from the Maven project to the Ant project.
    void
    copyProperties(org.apache.tools.ant.Project antProject, org.apache.maven.project.MavenProject mavenProject)
    Copy properties from the Ant project to the Maven project.
    void
     
    private String
    findFragment(org.apache.tools.ant.BuildException buildException)
     
    private org.apache.tools.ant.DefaultLogger
     
    private org.apache.tools.ant.types.Path
    getPathFromArtifacts(Collection<org.apache.maven.artifact.Artifact> artifacts, org.apache.tools.ant.Project antProject)
     
    void
    initMavenTasks(org.apache.tools.ant.Project antProject)
     
    private File
    Write the Ant target and surrounding tags to a temporary file

    Methods inherited from class org.apache.maven.plugin.AbstractMojo

    getLog, getPluginContext, setLog, setPluginContext

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAVEN_REFID_PREFIX

      public static final String MAVEN_REFID_PREFIX
      The prefix of all refid used by the plugin.
      See Also:
    • DEFAULT_MAVEN_PROJECT_REFID

      public static final String DEFAULT_MAVEN_PROJECT_REFID
      The refid used to store the Maven project object in the Ant build. If this reference is retrieved in a custom task, note that this will be a clone of the Maven project, and not the project itself, when the task is called through an ant task.
      See Also:
    • DEFAULT_MAVEN_PROJECT_REF_REFID

      public static final String DEFAULT_MAVEN_PROJECT_REF_REFID
      The refid used to store an object of type MavenAntRunProject containing the Maven project object in the Ant build. This is useful when a custom task needs to change the Maven project, because, unlike DEFAULT_MAVEN_PROJECT_REFID, this makes sure to reference the same instance of the Maven project in all cases.
      See Also:
    • DEFAULT_MAVEN_PROJECT_HELPER_REFID

      public static final String DEFAULT_MAVEN_PROJECT_HELPER_REFID
      The refid used to store the Maven project object in the Ant build.
      See Also:
    • DEFAULT_ANT_TARGET_NAME

      public static final String DEFAULT_ANT_TARGET_NAME
      The default target name.
      See Also:
    • UTF_8

      public static final String UTF_8
      The default encoding to use for the generated Ant build.
      See Also:
    • ANTLIB

      public static final String ANTLIB
      The path to The XML file containing the definition of the Maven tasks.
      See Also:
    • TASK_URI

      public static final String TASK_URI
      The URI which defines the built in Ant tasks
      See Also:
    • mavenProject

      @Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject mavenProject
      The Maven project object
    • session

      @Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session
      The Maven session object
    • projectHelper

      @Component private org.apache.maven.project.MavenProjectHelper projectHelper
      The Maven project helper object
    • pluginArtifacts

      @Parameter(property="plugin.artifacts", required=true, readonly=true) private List<org.apache.maven.artifact.Artifact> pluginArtifacts
      The plugin dependencies.
    • localRepository

      @Parameter(property="localRepository", readonly=true) protected org.apache.maven.artifact.repository.ArtifactRepository localRepository
      The local Maven repository
    • propertyPrefix

      @Parameter(defaultValue="") private String propertyPrefix
      String to prepend to project and dependency property names.
      Since:
      1.4
    • customTaskPrefix

      @Parameter(defaultValue="") private String customTaskPrefix
      The xml tag prefix to use for the built in Ant tasks. This prefix needs to be prepended to each task referenced in the antrun target config. For example, a prefix of "mvn" means that the attachartifact task is referenced by "<mvn:attachartifact>" The default value of an empty string means that no prefix is used for the tasks.
      Since:
      1.5
    • versionsPropertyName

      @Parameter(defaultValue="maven.project.dependencies.versions") private String versionsPropertyName
      The name of a property containing the list of all dependency versions. This is used for the removing the versions from the filenames.
    • tasks

      @Deprecated @Parameter private org.codehaus.plexus.configuration.PlexusConfiguration tasks
      Deprecated.
      Use target instead. For version 3.0.0, this parameter is only defined to break the build if you use it!
      The XML for the Ant task. You can add anything you can add between <target> and </target> in a build.xml.
    • target

      @Parameter private org.codehaus.plexus.configuration.PlexusConfiguration target
      The XML for the Ant target. You can add anything you can add between <target> and </target> in a build.xml.
      Since:
      1.5
    • sourceRoot

      @Deprecated @Parameter(property="sourceRoot") private File sourceRoot
      Deprecated.
      Use the build-helper-maven-plugin to bind source directories. For version 3.0.0, this parameter is only defined to break the build if you use it!
      This folder is added to the list of those folders containing source to be compiled. Use this if your Ant script generates source code.
    • testSourceRoot

      @Deprecated @Parameter(property="testSourceRoot") private File testSourceRoot
      Deprecated.
      Use the build-helper-maven-plugin to bind test source directories. For version 3.0.0, this parameter is only defined to break the build if you use it!
      This folder is added to the list of those folders containing source to be compiled for testing. Use this if your Ant script generates test source code.
    • skip

      @Parameter(property="maven.antrun.skip", defaultValue="false") private boolean skip
      Specifies whether the Antrun execution should be skipped.
      Since:
      1.7
    • exportAntProperties

      @Parameter(defaultValue="false") private boolean exportAntProperties
      Specifies whether the Ant properties should be propagated to the Maven properties.
      Since:
      1.7
    • failOnError

      @Parameter(defaultValue="true") private boolean failOnError
      Specifies whether a failure in the Ant build leads to a failure of the Maven build. If this value is false, the Maven build will proceed even if the Ant build fails. If it is true, then the Maven build fails if the Ant build fails.
      Since:
      1.7
  • Constructor Details

    • AntRunMojo

      public AntRunMojo()
  • Method Details

    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
      org.apache.maven.plugin.MojoFailureException
    • checkDeprecatedParameterUsage

      private void checkDeprecatedParameterUsage(Object parameter, String name, String replacement) throws org.apache.maven.plugin.MojoFailureException
      Throws:
      org.apache.maven.plugin.MojoFailureException
    • getConfiguredBuildLogger

      private org.apache.tools.ant.DefaultLogger getConfiguredBuildLogger()
    • addAntProjectReferences

      private void addAntProjectReferences(org.apache.maven.project.MavenProject mavenProject, org.apache.tools.ant.Project antProject) throws org.apache.maven.artifact.DependencyResolutionRequiredException
      Throws:
      org.apache.maven.artifact.DependencyResolutionRequiredException
    • getPathFromArtifacts

      private org.apache.tools.ant.types.Path getPathFromArtifacts(Collection<org.apache.maven.artifact.Artifact> artifacts, org.apache.tools.ant.Project antProject) throws org.apache.maven.artifact.DependencyResolutionRequiredException
      Parameters:
      artifacts - Artifact collection.
      antProject - Project
      Returns:
      Path
      Throws:
      org.apache.maven.artifact.DependencyResolutionRequiredException - In case of a failure.
    • copyProperties

      public void copyProperties(org.apache.maven.project.MavenProject mavenProject, org.apache.tools.ant.Project antProject)
      Copy properties from the Maven project to the Ant project.
      Parameters:
      mavenProject - MavenProject
      antProject - Project
    • copyProperties

      public void copyProperties(org.apache.tools.ant.Project antProject, org.apache.maven.project.MavenProject mavenProject)
      Copy properties from the Ant project to the Maven project.
      Parameters:
      antProject - not null
      mavenProject - not null
      Since:
      1.7
    • initMavenTasks

      public void initMavenTasks(org.apache.tools.ant.Project antProject)
      Parameters:
      antProject - Project
    • writeTargetToProjectFile

      private File writeTargetToProjectFile(String targetName) throws IOException
      Write the Ant target and surrounding tags to a temporary file
      Throws:
      IOException - problem with write to file
    • findFragment

      private String findFragment(org.apache.tools.ant.BuildException buildException)
      Parameters:
      buildException - not null
      Returns:
      the fragment XML part where the buildException occurs.
      Since:
      1.7