On Github nastevens / holygradle
Build configuration tool for the JVM
Build configuration tool for multiple languages
Groovy-based domain-specific language for software builds
Accurate but incomplete. Gradle supports more than just JVM languages. A little better, but "configuration" isn't quite right A mouthful, but the general ideaAll done in an environment with only the JDK installed*
Go from 'git clone' to running debug server in one command
Today I want to show you what Gradle is capable of
// build.gradle apply plugin: 'java'
package com.bitcurry.holynow; public class Demo { public static void main(String... args) { System.out.println("Imagine Whirled Peas"); } } mainClassName = 'com.bitcurry.holynow.HolyNow'
// build.gradle repositories { mavenCentral() } dependencies { compile group: 'org.glassfish.jersey.core', name: 'jersey-server', version: '2.7' compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.7' compile 'org.glassfish.jersey.media:jersey-media-moxy:2.7' }From here, going to jump into making small Java code files to implement our webservice
// build.gradle task wrapper(type: Wrapper) { gradleVersion = '1.9' }This will be the first time that closures and maps are introduced so I'll want to talk about the elements of this code
Valid Java == Valid Groovy
// repositories and dependencies are functions that takes a closure Closure repositoryConfig = { mavenCentral() } repositories(repositoryConfig) dependencies({ // compile is an overloaded function that works on a map or a string compile([group: 'org.glassfish.jersey.core', name: 'jersey-server', version: '2.7']) compile('org.glassfish.jersey.containers:jersey-container-servlet:2.7') compile('org.glassfish.jersey.media:jersey-media-moxy:2.7') })
buildscript { repositories { mavenCentral() } dependencies { compile 'com.sahlbach.gradle:gradle-jetty-eclipse-plugin:1.9.+' } } apply plugin: 'war' apply plugin: 'jettyEclipse'
Run ./gradlew build war jettyEclipseRun
task runDebug(dependsOn: [tasks.build, tasks.war]) { tasks.jettyEclipseRun.execute() }
apply plugin: 'groovy' dependencies { testCompile 'org.glassfish.jersey.core:jersey-client:2.7' testCompile 'org.glassfish.jersey.test-framework.providers:' + 'jersey-test-framework-provider-jetty:2.7' /* ^ developer paid by character in package name? */ testCompile 'org.codehaus.groovy:groovy-all:2.2.2' testCompile 'junit:junit:4.11' }Jump over to code for groovy test after slide
Put it in src/main/webapp
Have a beer!
dependencies { runtime 'org.webjars:jquery:2.1.0-2' }
<script src="webjars/jquery/2.1.0/jquery.min.js"></script>
Make sure to talk about jars getting auto-added to the classpath to make this work
class CompileCoffeeScript extends DefaultTask { @InputDirectory def srcDir = "src/main/coffee" @OutputDirectory def destDir = "${buildDir}/js" @TaskAction void doCompile() { /* ... */ } }
// buildSrc/build.gradle dependencies { compile 'ro.isdc.wro4j:wro4j-extensions:1.7.4' }
// build.gradle task compileCoffee(type: CompileCoffeeScript) { srcDir = file('src/main/coffee') destDir = new File($buildDir, 'js') }
// buildSrc/build.gradle dependencies { compile 'com.eriwen:gradle-js-plugin:1.9.0' }
// build.gradle apply plugin: 'js' combineJs { source = tasks.compileCoffee dest = new File(buildDir, 'all.js') } minifyJs { source = tasks.combineJs dest = new File(buildDir, 'all.min.js') sourceMap = new File(buildDir, 'all.sourcemap.json') } tasks.combineJs.dependsOn tasks.compileCoffee tasks.minifyJs.dependsOn tasks.combineJs