GRAILS.IO Avatar

Groovy Weekly #27 -- Guillaume Laforge's Blog

See how you can contribute to Groovy.

Generating Pretty Groovy 2.3 Groovydocs with Gradle

In some projects we have to build with an earlier version of Groovy, but given that Groovy 2.3.x introduced such pretty Groovydocs it would be a shame to lose out on the improved format.

Fortunately Gradle saved the day. To use the new format in a Gradle project simply define a new configuration:

configurations {
   groovyDoc
}

Then define the necessary dependencies using this new configuration:

dependencies {
    groovyDoc 'org.codehaus.groovy:groovy-groovydoc:2.3.3'
    groovyDoc 'org.codehaus.groovy:groovy-ant:2.3.3'
}

Finally configure the groovydoc task to use the configuration:

  groovydoc {
     groovyClasspath = configurations.groovyDoc
  }

Publishing a POM with Gradle

Recently for the Grails 2.4.x releases I was looking for a way to automate publishing a pom.xml file to Maven central.

Currently, Gradle makes it pretty easy to upload JAR files with signing etc. but there is no way to publish just a POM.

Anyway the solution ended up being to use maven-ant-tasks (I tried the aether-ant-tasks but had trouble getting them to work):

configurations {
    mavenAntTasks
}
dependencies {
    mavenAntTasks 'org.apache.maven:maven-ant-tasks:2.1.1'
}

With these in place to write an install target that publishes your pom.xml locally you can use the install ant task:

task install(dependsOn:assemble) << {
    def antBuilder = services.get(IsolatedAntBuilder)
    antBuilder.withClasspath(configurations.mavenAntTasks).execute {
        taskdef(resource: 'org/apache/maven/artifact/ant/antlib.xml')
        install(file:"${buildDir}/pom.xml") {
            pom refid:"pom"
        }
    }
}   

Finally, for upload to Maven central you need GPG signatures etc. so this requires using the maven-gpg-plugin to deploy:

task uploadPublished(dependsOn:install) << {
    def antBuilder = services.get(IsolatedAntBuilder)
    antBuilder.withClasspath(configurations.mavenAntTasks).execute {
        taskdef(resource: 'org/apache/maven/artifact/ant/antlib.xml')
        def isSnapshot = version.endsWith("-SNAPSHOT")
        def url = isSnapshot ? "https://oss.sonatype.org/content/repositories/snapshots/" : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
        def repoId = isSnapshot ? "sonatype-nexus-snapshots" : "sonatype-nexus-staging"
        mvn {
            arg value:"org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file"
            arg value:"-Durl=${url}"
            arg value:"-DrepositoryId=${repoId}"
            arg value:"-DpomFile=${buildDir}/pom.xml"
            arg value:"-Dfile=${buildDir}/pom.xml"
            arg value:"-Pgpg"
        }

    }
}

Now you can run gradle install to install to your local Maven repo and gradle uploadArchives to upload your signed pom.xml.

For reference here is the complete build.gradle.

Road to Grails 2.3: Milestone 2 Out Now

Two New Netflix Open Source Grails Apps

Netflix OSS is continuing to grow in its usage of Grails. Checkout Liptstick and Ice.