Setting a private Maven repository on JFrog Bintray for a Grails 2.4 plugin

If you are like me, looking for a private Maven repository to share your Grails 2 plugin just among your team and are still waiting for Grails 3 to get more mature, this is the right place. I am going to show in a total of three posts, distinct services that can be used to achieve this goal.

Here are some available options :

The first three options will not be covered in this series of posts. Both options require you to install and manage a Maven repository by yourself (this includes: rent/buy a server, make it secure, setup network ports, etc). Since the focus of this and the next tutorials is to quickly setup and deploy private plugins to the cloud, I won’t show examples on how to configure and run both , , and .

So, the next in the list, is . If you have been following the new changes from Grails 2 to Grails 3 and its switch from Maven to Gradle as its build automation system, you probably heard of or are familiar with Bintray. You can search and publish your public , for free. But what if you need to publish a private plugin? You can do everything at the same place, at a starting cost of .

The following explanation on how to setup a Grails plugin is based on this where you can take a look if you need more details. I am running Java 1.7.0_79, Grails 2.4.4, Groovy 2.4.5, and Maven 3.3.3.

Creating a plugin

We can start creating a new Grails plugin:

> grails create-plugin sample-plugin

Update the BuildConfig.groovy file of your new plugin with the newest version of the release plugin ( to get the most up to date maven dependencies) and add the Tomcat plugin ( quick way to solve an , if you know a better solution, please leave a comment ) as follows:

plugins {
  build "org.grails.plugins:release:3.1.2"
  build ":tomcat:7.0.55"
}

The create-plugin command will generate almost the same objects as a Grails application generates. The main difference is the plugin descriptor file, which in my case is called SamplePluginGrailsPlugin.groovy. In this file, you can set the plugin’s version, authors etc.

Next, generate the pom.xml file:

> grails create-pom com.yourcompany

It will look like the following:

<groupId>com.yourcompany</groupId>
<artifactId>sample-plugin</artifactId>
<packaging>grails-plugin</packaging>
<version>0.1</version><name>sample-plugin</name>
<description>sample-plugin</description><properties>
    <grails.version>2.4.4</grails.version>
    <h2.version>1.3.170</h2.version>
</properties><dependencies>
    ...
</dependencies><build>
  <pluginManagement/>
  <plugins>
    ...
  </plugins>
  <repositories>
    ...
  </repositories>
</build>

Now, I am going to add a service called HelloWorldService just for testing purposes.

package sample.pluginclass HelloWorldService {  public void hello(String name){
     println "hello ${name}"
  }
}

At this point, you should be able to test if everything is working fine by using the following command (make sure you have the Maven command line available — brew install maven — if you are using Mac )

>mvn package -DskipTests
...
[INFO] — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
[INFO] BUILD SUCCESS
[INFO] — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
...

Configuring your Bintray account

You can get a trial silver plan and then, from your profile page, create a new repository.

Then give it a name. I am going to name my repository as target and select Maven as its type.

After created, click on Convert to Premium (in order to turn it into a private repo later).

Then, click on Edit. From the opened left menu, select Permissions:

Next, click on Make Private. Ok, now go back to the previous window, click on the green button called Add New Package and name your new package as you want. I am going to name my package as madmaxplugin. After configured, click on the path to your repository and a window describing the status of your package should appear, as follows:

Click on SET ME UP. A list of configuration options will be shown. Select Uploading and then Deploying with Maven

Configuring your plugin

Now, add the second item of the above list to your plugin’s pom.xml. Next, we need to configure Maven to connect to Bintray. Open your ~/.m2/settings.xml. According to the :

There are two locations where a settings.xml file may live:

The Maven install: $M2_HOME/conf/settings.xml

A user’s install: ${user.home}/.m2/settings.xml

Tip: If you need to create user-specific settings from scratch, it’s easiest to copy the global settings from your Maven installation to your ${user.home}/.m2 directory. Maven’s default settings.xml is a template with comments and examples so you can quickly tweak it to match your needs.

So, if you cannot find the local settings file, like me, just copy from the global configuration file. ( if you want, you can make all changes to the global settings file, rather than configuring a private settings.xml just for the current user) . To find the global configuration file, just get the Maven home folder by typing:

> mvn —version
Apache Maven 3.3.3 
Maven home: /usr/local/Cellar/maven/3.3.3/libexec
Java version: 1.7.0_79, vendor: Oracle Corporation
...

Then, you will be able to find the settings.xml inside of the conf folder and copy it to your local m2 folder. Next open your local settings.xml and choose an id and include your credentials to the servers list:

<servers>
  <server>
    <id>bintray-pargles-target</id>
    <username>pargles</username>
    <password>**********</password>
  </server>
</servers>

To get your password from Bintray, open your profile, select edit, then, click on API Key and finally click on the right button Show.

If both settings.xml and pom.xml are configured, it is time to deploy your plugin.

> mvn deploy -DskipTests
...
[INFO] — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
[INFO] BUILD SUCCESS
[INFO] — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
...

Testing your private plugin

In order to test if the plugin is available for your apps, lets create a test app

> grails create-app mytestapp

In order to include your Bintray package to your BuildConfig.groovy file, click on SET ME UP button again, select Downloading and then Resolving artifacts using Gradle. From there you can find the url and username to connect with your repository.

Your plugin path should also be available at the bottom of your package page, like the following:

At the end, your BuildConfig.groovy will look like as the following:

repositories {
 inherits true 
 ...
 mavenRepo(url: "http://pargles.bintray.com/target"){
  auth([
   username: "pargles",
   password: "******************************************"
  ])
 }
 ...
}
plugins {
 ...
 compile "com.yourcompany:sample-plugin:0.1"
}

If you want hide your credentials, you can take a look at . Now, a quick test, add your new service to your BootStrap.

import sample.plugin.HelloWorldServiceclass BootStrap {
  HelloWorldService helloWorldService 
  def init = { servletContext ->
     println helloWorldService.hello("pargles")
  }
  def destroy = {
  }
}

And, run your app.

> grails run-app

Done , you and your team are ready to go secretly !

If you are looking for a tutorial on how to set a public repository on Bintray for your Grails 3 app, take a look at this post written by Benoit:

Please leave your comments, suggestions or questions. Thanks :)

ROSS Intelligence’s Technical Blog

ROSS Intelligence builds technologies to help lawyers scale. Here we will share interesting and useful tech related things that we find along the way.

Pargles Dall'Oglio

Written by

Backend Engineer and co-founder of ROSS Intelligence. Enthusiast in Artificial Intelligence, Groovy/Grails, performance optimization, video compression …

ROSS Intelligence’s Technical Blog

ROSS Intelligence builds technologies to help lawyers scale. Here we will share interesting and useful tech related things that we find along the way.