[
http://jira.codehaus.org/browse/MGROOVY-189?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=167327#action_167327
]
Jason Dillon commented on MGROOVY-189:
--------------------------------------
Here is a wee example for you:
{code}
import org.codehaus.groovy.maven.mojo.GroovyMojo
import org.apache.maven.project.MavenProject
import org.apache.tools.ant.types.Path
/**
* Simple mojo to display some classpath muck.
*
* @goal display-classpath
*
* @version $Id$
*/
class DisplayClassPathMojo
extends GroovyMojo
{
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
MavenProject project
/**
* @parameter expression="${plugin.artifacts}"
* @required
* @readonly
*/
List pluginArtifacts
void execute() {
println "Classpaths:"
Path p
p = new Path(ant.antProject)
p.path = project.compileClasspathElements.join(File.pathSeparator)
println " Compile=${p}"
p = new Path(ant.antProject)
p.path = project.runtimeClasspathElements.join(File.pathSeparator)
println " Runtime=${p}"
p = new Path(ant.antProject)
p.path = buildPluginClassPath()
println " Plugin=${p}"
}
private Path buildPluginClassPath() {
if (pluginArtifacts == null) {
return new Path(ant.antProject)
}
List files = []
pluginArtifacts.each { artifact ->
files << artifact.file
}
Path path = new Path(ant.antProject)
path.path = files.join(File.pathSeparator)
return path
}
}
{code}
For the runtime, compile, etc classpaths its very simple, for the plugins
classpath a bit more work, but still quite simple.
> Access Maven Classpaths for Ant Tasks
> -------------------------------------
>
> Key: MGROOVY-189
> URL: http://jira.codehaus.org/browse/MGROOVY-189
> Project: GMaven
> Issue Type: Improvement
> Components: examples
> Affects Versions: 1.0-rc-5
> Environment: gmaven 1.0-rc4
> Reporter: Les Hazlewood
> Assignee: Jason Dillon
> Priority: Critical
> Fix For: 1.1
>
>
> One of my biggest desires for the GMaven plugin is the ability to encapsulate
> legacy Ant build targets in a Maven plugin using the Ant Builder. This
> allows people to configure a Maven plugin as expected without knowledge of
> Ant (or Groovy of course) being used 'under the hood'. Granted, this is
> already available today, but it is missing one big thing that I know of that
> precludes many Ant tasks from running:
> Any ant scripts require a taskdef definition. e.g.:
> ant.taskdef( name: "blah", classname:"some.pkg.FQCN", classpath:"$aClasspath"
> )
> It doesn't appear that there is any way to access a Maven classpath to
> achieve this. The Maven AntRun plugin for example generates 4 classpaths:
> maven.compile.classpath
> maven.runtime.classpath
> maven.test.classpath
> maven.plugin.classpath
> It would be greatly beneficial if GMaven also enabled these (or similar)
> classpaths for use with the Ant Builder, then we could encapsulate all Ant
> details inside a GMaven plugin and the plugin consumer never needs to know
> these details. Perhaps use the AntRun plugin's support for this?
> Until then, our POMs must be littered with numerous unsightly embedded ant
> xml chunks (via the maven-antrun-plugin) since we need access to many 3rd
> party ant tasks that do not have a maven plugin equivalent. It'd be much
> nicer to hide this away from the POM configurer via a GMaven-based plugin
> with normal Maven configuration attributes.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email