Adding private module repositories

With the release of play 1.2 and its new dependency management it is very easy to have private repositories where you can store your own modules.

As the dependency management of Play is based on Apache Ivy, it is theoretically possible to use a Maven repository for this task, but often it is simpler to use a small share on your Intranet web server for such task.

Getting ready

You should have some location, where you can upload your modules. If you just do this for testing purposes, you can start a web server via Python

python -m SimpleHTTPServer

This will start a web server on port 8000 with the current directory you are in as document root.

How to do it...

When creating a new module, it is not necessary to set a version number in the modules conf/dependencies.yml file. However, if you do it, it helps you to keep module versions. So, for test reasons, go into one of your modules, set version to 0.1 and build the module. Then copy the created zip from the dist/ directory into the directory, where you started the web server or alternatively in the directory of your real web server. Repeat the steps again, but this time create a module using 0.2 as version. Going to http://localhost:8000 should now provide a listing with two zip files of your module.

Now add another repository to your application specific conf/dependencies.yml file:

require:
    - play
    - spinscale -> csv-module 0.1

# Custom repository
repositories:
    - spinscaleRepo:
        type:       http
        artifact:   "http://localhost:8000/[module]-[revision].zip"
        contains:
          - spinscale -> *

Now you can run play dependencies and the output should include this:

~ Installing resolved dependencies,
~
~    modules/csv-module-0.1

Normal JAR dependencies are put in the lib/ directory of your application; however modules like the referenced csv-module are unpacked into the modules/ directory inside of your Play application. Whenever you are starting your application now, all the modules in this directory are loaded automatically.

How it works...

The most important part is the format of the artifact in the dependencies file. It allows you to match arbitrary directory structures on the web server. Furthermore, you can possibly also have local repositories by using an artifact definition like the following:

artifact:   "${play.path}/modules/[module]-[revision]"

Always keep in mind not to use tabs in the YML files, but spaces when editing them. Furthermore, the artifact path has to be absolute.

If you want to remove a module, delete the entry from the dependencies file, and execute play dependencies --sync again to make sure all modules are removed from your application as well.

There's more...

Even though it is possible to have private repositories, you are of course encouraged to open source your modules.

Check the official documentation

There is an own page about dependency management where most of the possible options are written down, as there are still some more possibilities. Please read most of it at http://www.playframework.org/documentation/1.2/dependency.

Repositories with older versions

It is not simple to use any of the dependencies here with Play versions older than 1.2. There has been an effort at http://code.google.com/p/play-repo/ - but it looks like it is not in active development anymore.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.61.170