I want to create an Ant buildfile, that includes some files as a sort of plugin.
So if I want to activate a feature in a project – say pmd-checking – I copy a pmd.xml in a directory and the build.xml get on the start the idea, that pmd.xml exists and imports it, so that new targets can be available to the build.
But the ‘import’ task can only be used as a top-level task, so I have no idea how to relize this functionality. Is this possible with Ant and if so, how can I do it?
EDIT: I would prefer a solution, that allows new targets to show up in the listing presented by ant -p.
It’s not explicitly stated in the import task documentation, but the task accepts a fileset as an alternative to a single file.
Hence this, at the top level, should do the trick, and targets created are listed by
ant -p:One wrinkle with this is that there must be at least one plug-in in the ‘plugins’ directory, or the import will fail.
You can just create a placeholder file – say called
empty.xml:Once that’s there, you just need to put any new plug-ins in the plugin directory, and they will be imported by future builds.