Thanks for all of your help everyone. I used the dependency method, which
I found to be much superior to plugin:download or plugin:install since a
user may not have permissions to install a plugin into the
MAVEN_HOME/plugins directory. With the dependency method, I found it
difficult to upgrade the plugin unless I manually deleted what was
installed or specified SNAPSHOT as the version. After reading some older
mailings(specifically between Ben Gridley and Brett Porter), I used
modified Ben's script as follows:
<?xml version="1.0"?>
<project
xmlns:j="jelly:core"
xmlns:ant="jelly:ant">
<goal name="ccplugin:delete">
<j:forEach var="dep" items="${pom.dependencies}">
<j:if test="${dep.type =='plugin'}">
<!--
<maven:get plugin="${dep.artifactId}" property="plugin"
var="plugin" />
-->
<!-- Clean out the cache files -->
<attainGoal name="plugin:uninstall" />
<!-- Set the variables -->
<j:set var="groupId" value="${dep.groupId}"/>
<j:set var="artifactId" value="${dep.artifactId}"/>
<j:set var="version" value="${dep.version}"/>
<j:set var="pluginname" value="${artifactId}-${version}"/>
<!-- Check if the plugin is in the main maven plugins directory -->
<ant:available property="mainplugin"
file="${maven.plugin.dir}/${pluginname}.jar" />
<j:if test="${mainplugin == 'true'}">
<ant:echo message="${maven.plugin.dir}/${pluginname}.jar is in
the main maven plugins directory" />
<!-- This is kindof dangerous as it would effect all users and
may fail if not owned by the user -->
<ant:delete file="${maven.plugin.dir}/${pluginname}.jar" />"
</j:if>
<!-- Remove from the user's plugin directory. -->
<ant:available property="userplugin"
file="${maven.plugin.user.dir}/${pluginname}.jar" />
<j:if test="${userplugin == 'true'}">
<ant:echo message="Removing '${pluginname}' from
'${maven.plugin.dir}'" />
<ant:delete file="${maven.plugin.user.dir}/${pluginname}.jar" />"
</j:if>
<!-- Remove from the user's cache directory. This isn't really
necessary since we'll delete
the jar in the repository which will cause the plugin to be
re-downloaded -->
<ant:available property="usercache"
file="${maven.plugin.unpacked.dir}/${pluginname}" />
<j:if test="${usercache == 'true'}">
<ant:echo message="Removing ${pluginname} from
${maven.plugin.unpacked.dir}" />
<ant:delete dir="${maven.plugin.unpacked.dir}/${pluginname}"
includeEmptyDirs="true" />
</j:if>
<!-- Remove from the user's repository directory. -->
<ant:available property="userrepoplugin"
file="${maven.repo.local}/${groupId}/plugins/${pluginname}.jar" />
<j:if test="${userrepoplugin == 'true'}">
<ant:echo message="Removing '${pluginname}' from
'${maven.repo.local}'" />
<ant:delete
file="${maven.repo.local}/${groupId}/plugins/${pluginname}.jar" />
</j:if>
</j:if>
</j:forEach>
</goal>
</project>
I think this kind of functionality might be useful in the main Maven
plugin plugin. I'm adding this to jira for the maven-plugin-plugin project
as a 'wish' issue type.
Eric