| 1 | <h2>Full example</h2> |
| 2 | <pre><code>apply plugin: "java" |
| 3 | apply plugin: "eclipse" |
| 4 | apply plugin: "idea" |
| 5 | |
| 6 | group = "com.mycompany.hadoopproject" |
| 7 | version = "1.0" |
| 8 | |
| 9 | repositories { |
| 10 | // Standard Maven |
| 11 | mavenCentral() |
| 12 | maven { |
| 13 | url "https://repository.cloudera.com/artifactory/cloudera-repos/" |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | // Mimic Maven 'provided' configuration, as suggested in GRADLE-784 |
| 18 | configurations { |
| 19 | provided |
| 20 | } |
| 21 | sourceSets { |
| 22 | main { |
| 23 | compileClasspath += configurations.provided |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | ext.hadoopVersion = "2.0.0-mr1-cdh4.0.1" |
| 28 | dependencies { |
| 29 | provided "org.apache.hadoop:hadoop-client:${hadoopVersion}" |
| 30 | |
| 31 | // Example of adding a specific compile time dependency |
| 32 | compile "com.google.guava:guava:11.0.2" |
| 33 | |
| 34 | testCompile "junit:junit:4.8.2" |
| 35 | } |
| 36 | |
| 37 | // Java version selection |
| 38 | sourceCompatibility = 1.6 |
| 39 | targetCompatibility = 1.6 |
| 40 | |
| 41 | eclipse { |
| 42 | classpath { |
| 43 | // Ensure Eclipse build output appears in build directory |
| 44 | defaultOutputDir = file("${buildDir}/eclipse-classes") |
| 45 | // Ensure the provided configuration jars are available in Eclipse |
| 46 | plusConfigurations += configurations.provided |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // Emulate Maven shade plugin with a fat jar. |
| 51 | // http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-Creatingafatjar |
| 52 | jar { |
| 53 | from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } |
| 54 | }</code></pre> |