{"id":16784818,"url":"https://github.com/odavid/ant-based-mojo-example","last_synced_at":"2026-02-02T03:35:37.795Z","repository":{"id":29042606,"uuid":"32570181","full_name":"odavid/ant-based-mojo-example","owner":"odavid","description":null,"archived":false,"fork":false,"pushed_at":"2015-05-01T00:14:54.000Z","size":144,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-23T08:41:23.261Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/odavid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-20T07:48:06.000Z","updated_at":"2019-07-10T17:52:06.000Z","dependencies_parsed_at":"2022-09-06T00:11:17.994Z","dependency_job_id":null,"html_url":"https://github.com/odavid/ant-based-mojo-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odavid%2Fant-based-mojo-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odavid%2Fant-based-mojo-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odavid%2Fant-based-mojo-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odavid%2Fant-based-mojo-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/odavid","download_url":"https://codeload.github.com/odavid/ant-based-mojo-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243941735,"owners_count":20372296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T08:07:17.859Z","updated_at":"2026-02-02T03:35:37.668Z","avatar_url":"https://github.com/odavid.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ant Based Maven Plugins\n\nThe following repository is dedicated to explain how to create Ant based Maven plugins.\n\n## Why Ant Based Maven Plugin\n\nMany legacy Java application build scripts are Ant based. \nWhen a decision is made to convert that code to Maven, usually we start by taking pieces of Ant code and using it internally using antrun plugin. This makes the Maven pom files verbose and hard to maintain. Re-implementing the Ant code as a Maven Plugin can be a tedious work. \nAn Ant based mojo can ease the migration from Ant to Maven, by keeping the pom files clean and using declarative Maven plugins configuration, while the actual code can be still using Ant scripts.\n\n## Getting started\n\nA Maven plugin is a jar artifact with the the following convention: \n\n* artifactId: ${plugin-name}-maven-plugin\n* packaging: maven-plugin\n\nIn order to start developing an Ant based mojo, you need to the following project structure:\n\n```\npom.xml \t\t\t\t\t\t\t\t\t  \nsrc/main/scripts/${plugin-name}.build.xml     (ant build script)\nsrc/main/scripts/${plugin-name}.mojo-desc.xml (simple mojo descriptor)\n```\n\n## The pom.xml file\n\nThe Ant Based Plugin must have few dependencies and few plugins defined in order to work.\nI've created an [example parent pom](../../blob/master/ant-mojos-parent/pom.xml) and a [child maven-plugin](../../blob/master/helloworld-maven-plugin/pom.xml) that contains the minimal settings that are needed in order to create Ant based Maven Plugins\n\n## The ${plugin-name}.mojo-desc.xml file\n\nAny Maven plugin is composed of Mojos. Each Mojo implements a single goal and gets its own configuration parameters.\nEach parameter has a name, default value and an expression that is bounded to a property to allow configuration of the mojo parameter from the command line by referencing a system property that the user sets.\n\nA mojo definition can also inherit from an abstract mojo definition, which allow several mojos to share the same parameters.\n\nAn example for the mojo descriptor file can be found in [here](../../blob/master/helloworld-maven-plugin/src/main/scripts/helloworld.mojo-desc.xml)\n\n## The ${plugin-name}.build.xml file\n\nThis file is actually a pure Ant build script. Each mojo should have a corresponding Ant target with the same name.\nThere is a boilerplate code that needs to be set in order to get connectivity with Maven properties and API\n\n```\n\u003cproject\u003e\n\t\u003c!-- *************************************************************************** --\u003e\n\t\u003c!-- Boilerplate - Add this to any Ant based Plugin --\u003e\n\t\u003ctaskdef resource=\"net/sf/antcontrib/antlib.xml\"/\u003e\n\t\u003ctaskdef resource=\"org/apache/maven/ant/tasks/antlib.xml\"/\u003e\n\t\u003cmavenclasspath/\u003e\n\t\u003cimportmavenprojectproperties/\u003e\t\n\t\u003c!-- *************************************************************************** --\u003e\n\n\t\u003c!-- Mojo Target - target name equals to the mojo name, all mojo parameters are exposed as ant properties --\u003e\n\t\u003ctarget name=\"hello-world\"\u003e\n\t\t\u003cecho\u003eThe following is a basic ant based mojo, it takes to parameters and prints them to the screen...\u003c/echo\u003e\n\t\t\u003cecho\u003e${message} ${name}\u003c/echo\u003e\n\t\u003c/target\u003e\n\u003c/project\u003e\n```\n\nAn example for the mojo build.xml file can be found in [here](../../blob/master/helloworld-maven-plugin/src/main/scripts/helloworld.build.xml)\n\n\n## List of Maven Ant tasks\n\nThe following are useful ant tasks that let a plugin developer to exploit \"Maven echosystem\" within the context of Ant project.\nIn order to use these tasks, the plugin developer need to add the following taskdef within the build code\n\n\n##### mavenclasspath\n\nThe mavenclasspath task exposes maven dependencies as path properties. This task is part of the boilerplate code\n\n* ${compile_classpath} - all compile dependencies\n* ${plugin_classpath} - all plugin dependencies\n* ${combined_classpath} - a combination of compile and plugin dependencies\n* ${test_classpath} - all test dependencies\n\n##### importmavenprojectproperties\n\nBy using this task, all maven project.* properties are available within the Ant build context such as ${project.basedir}, ${project.build.directory} ${project.build.finalName}, etc...\nThis task is part of the boilerplate code\n\n##### attachartifact\n\nAttaching a file as additional artifact to the project running the plugin\n\n```\n\u003cattachartifact file=\"\" type=\"\" classifier=\"\"/\u003e\n```\n\n##### export-pom-property\n\nExports a property to Maven context, so it can be used by other plugin configuration\n\n```\n\u003cexport-pom-property property=\"\u003cthe-name-of-the-property\u003e\" value=\"\u003cvalue-from-ant\u003e\" overwrite=\"true|false (default=false)\"/\u003e\n```\n\n##### execute-maven-plugin\n\nSometimes you want to execute a goal of other plugin within your plugin, so the operation of the plugin will be atomic.\n\nFor example\n```\n\u003ctarget name=\"my-mojo\"\u003e\n\t...\n\t...\n\t\u003cecho\u003eCopying some dependencies to ${project.build.directory}/alternateLocation\u003c/echo\u003e\n\t\u003cexecute-maven-plugin artifactId=\"maven-dependency-plugin\" groupId=\"org.apache.maven.plugins\" version=\"2.10\" goal=\"copy-dependencies\"\u003e\n\t\t\u003cconfiguration\u003e\n\t\t\t\u003cincludeGroupIds\u003e${project.groupId}\u003c/includeGroupIds\u003e\n\t\t\t\u003coutputDirectory\u003e${project.build.directory}/alternateLocation\u003c/outputDirectory\u003e\n\t\t\u003c/configuration\u003e\n\t\u003c/execute-maven-plugin\u003e\n\t...\n\n\u003c/target\u003e\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodavid%2Fant-based-mojo-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fodavid%2Fant-based-mojo-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodavid%2Fant-based-mojo-example/lists"}