Java – How to install Grails plugins through Maven pom.xml

grailsjavamavenplugins

I'm building a Grails project with Maven, which is the required way of building at my company.

On my local machine, I have installed a Grails plugin in the usual way grails install-plugin foo. Of course, when the project is built by Maven on the build server, it knows nothing about this plugin.

I've seen that the following can be useful for the case where the plugin is available in the plugins directory of Grails:

<plugin> 
  <groupId>org.grails</groupId> 
  <artifactId>grails-maven-plugin</artifactId> 
  <version>1.1</version> 
  <extensions>true</extensions> 
  <executions> 
    <execution> 
      <id>create plugins folder</id> 
      <phase>validate</phase> 
      <goals> 
        <goal>install-plugin</goal> 
      </goals> 
      <configuration> 
        <pluginUrl>${env.GRAILS_HOME}/plugins/grails-hibernate-1.1.zip</pluginUrl>                 
      </configuration> 
    </execution> 
  </executions>           
</plugin> 

but suppose the plugin was not on the machine at all? What would the pluginUrl be in the case where Maven or Grails will need to go to the internet to find the plugin?

Edit:

I've found that the pluginName and pluginVersion tags are useful, and I've added the following execution to the grails-maven-plugin:

<execution>
  <id>Hibernate plugin</id>
  <phase>validate</phase>
  <goals>
    <goal>install-plugin</goal>
  </goals>
  <configuration>
    <pluginName>hibernate</pluginName>
    <pluginVersion>1.3.7</pluginVersion>
  </configuration>
</execution>

This almost works. If I check out my code in a new directory, and delete the contents of my plugins directories, Maven is able to build the project, successfully finding all plugin dependencies.

Yet it still doesn't work on the build server. Any ideas?

Best Answer

Try adding this dependency to your pom.xml

<dependency>
    <groupId>org.grails.plugins</groupId>
    <artifactId>fields</artifactId>
    <version>1.3</version>
    <type>zip</type>
    <scope>runtime</scope>
</dependency>

when you recompile your App maven will download and install the plugin

Related Topic