How to download and evoke a maven plugin?


(sirinath1978m) #1

How to download and evoke a maven plugin?


(Adam Murdoch) #2

This isn’t possible. We hope to add something like this after the Gradle 1.0 release.


(sirinath1978m) #3

How long down the line is this?


(sirinath1978m) #4

I am trying to convert a maven project. My biggest worries are the plugin functionality.


(Peter Niederwieser) #5

It’s a high priority for post-1.0. We don’t have a date at this point.


(Hans Dockter) #6

For some plugins there is a way to do this today. It is not very convenient but might be an option. Whether you can run a plugin like this, depends on the properties it is using. If those are standard properties it is no problem to inject them from Gradle. If they use Maven domain objects, for example a Maven project object to retrieve information about the dependencies, the following will not work.

What is your scenario? Do you want to reuse custom plugins of your enterprise or standard Maven plugins?

buildscript {
 repositories {
  mavenLocal()
  mavenCentral()
 }
 dependencies {
  classpath "org.sonatype.mavenbook.plugins:first-maven-plugin:1.0-SNAPSHOT"
 }
}
  task testPlugin << {
 def mojo = new org.sonatype.mavenbook.plugins.EchoMojo()
 mojo.message = "Hello from Gradle"
 mojo.execute()
}

The Maven plugin is an example from the Maven book. You need to install it to your local repo. For more details see here: http://books.sonatype.com/books/mvnref-book/reference/writing-plugins-sect-custom-plugin.html


(sirinath1978m) #7

this is interesting. thanks


(John Norris) #8

The line in the example code of def mojo = new org.sonatype.mavenbook.plugins.EchoMojo()

Should that be

org.sonatype.mavenbook.plugins.first-maven-plugin.EchoMojo()?

And will this work a mojo that we have written that takes a set of params?


(John Norris) #9

Done some further work. Yes, it should be org.sonatype.mavenbook.plugins.EchoMojo() Also, looking at the maven book, EchoMojo class is a goal of echo. But within gradle, the goal is not called as it would be within mvn. Instead it is the class that is called. So got there eventually