Friday Repost: Making Grails work behind an proxy server

The Friday Repost series are copies from my earlier writings. Since I don’t want to loose them, and they might prove useful to others, I’m reposting them on this blog.

Making Grails work behind an NTLM firewall (or using Grails without Internet)

Currently, I’m in the process of taking over an existing Grails project and migrating it to a different location. This location has been setup by me, so I have full control over it, except for one tiny detail: the Proxy Server.

The application used to work great, and installing plugins was a breeze: just do a good old ‘grails install-plugin fitnesse’, and the plugin would be installed. However, since this Proxy Server is not just any Proxy Server, but a Microsoft NTLM Proxy Server, we tried quite hard to make Java work with it, but at the moment the score is 1-0 for the Proxy Server. This gives us the following problems:

1) Our dependencies cannot be downloaded
2) Our plugins cannot be be downloaded
3) Some plugins cannot be installed anymore

Downloading dependencies
In our BuildConfig.groovy, we specified some dependencies like joda time and xstream. These dependencies are normally downloaded, but due to our Proxy issue, that doesn’t work.

Our solution to this is to use Nexus. Nexus is able to pass the firewall, and can download our dependencies. It serves as a transparent Maven proxy, which can also be used by Ivy, and solves our problem nicely. Besides, it’s a good idea to install a local Maven proxy anyway, mostly because of reliability, but also because of speed and making sure everyone uses the same dependencies.

Downloading plugins
Unfortunately, the Grails plugins are not in a Maven repository. However, a solution to this is to download the plugin zip (eg grails-fitnesse-0.2.zip), rename it (to fitnesse-0.2.zip), put it in the lib directory (even though I’m really not a fan of putting binaries in version control systems), and register it in the application.properties and BuildConfig.groovy.

The BuildConfig.groovy should look like this:

grails.project.dependency.resolution = {
    inherits "global" // inherit Grails' default dependencies
    log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    repositories {
        mavenRepo "http://172.30.60.106:8081/nexus/content/repositories/central" // nexus repo
    }
    dependencies {
        compile ('com.thoughtworks.xstream:xstream:1.3.1') {
            excludes "stax","stax-api"
        }
    }

    plugins {
        runtime ':hibernate:1.3.2'
        runtime ':tomcat:1.3.2'
        runtime ':fitnesse:0.2'
    }

As you can see, everything is configured here: the dependencies are here, the location to nexus is configured, and there’s a plugin closure. This “plugins” closure defines the plugins, and allows you to place them in the ‘lib’ directory. Be sure to rename the plugin zip to remove the ‘grails’ part, else it doesn’t work. Maybe these zips are also available from a Maven repository, which would solve the issue of putting binaries in our source control system, but I haven’t been able to find them yet.

Plugin installation
Some plugins, like the jQuery plugin, but also like my own plugin, the syntax-highlighter, download resources from the Internet when installing them. I haven’t been able to work around that yet, but my current solution is to just not use those plugins. I downloaded the jQuery javascript libraries and attached them to the project myself, and since we only use jQuery which does that, this solution is also an adequate fix.

Conclusion
So, as you can see, with some effort, it’s possible to make Grails work behind a Proxy Server, or without internet at all. This is a good solution for build servers, so you can have reproducible builds without the need for an Internet connection.

8 Comments

  1. Gethin James

    I download the Grails pluglins, then manually install them in our local Maven repo – in your case Nexus. Then you don’t need to mess about with putting things in the lib directory.

    Also “inherit false” works better for BuildConfig.groovy

  2. Gethin James

    Also @pledbrook tweeted today that:

    “an –offline option has been added to #grails HEAD. I’ll be testing it soon.”

    See http://j.mp/n993KJ

    • Based on the tweet, it’s a bit hard to say what it does. Do you have more information? Does it mean that no dependency resolution would be done? Cause that would be a nice improvement in startup time.

  3. We are also behind corporate proxy server but common grails proxy settings work fine in our case. We have something like the following in ProxySettings.groovy

    myproxy=["http.proxyHost":"companyproxyserver", "http.proxyPort":"8080", "http.proxyUserName":"myuser", "http.proxyPassword":"mypassword"]
    currentProxy=”myproxy”

    Have you tried similar config in your case?

    • Hi Leo,

      We’ve tried that, but it didn’t work with our proxy server. Did you also use a Microsoft NTLM proxy server?

      Erik

    • Could you please let me know if you how to use .pac file for proxy for grails?

      • Hi Siva, I’m sorry, but I have no experience with .pac files. I know you can open them, they are just txt files, and with a bit luck, depending on the complexity of the pac, you might be able to find the correct configuration there.

  4. Hi!

    We are using Artifactory as a local Maven provy and it works great.
    It speeds up building Grails apps (when it’s downloading th whole internet)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>