Monday, June 17, 2013

Gradle templates

// Generate a new Groovy Project Qwickly (tm) //
// source: https://github.com/townsfolk/gradle-templates

// in build.gradle file (in the project's root folder):
apply from: 'http://www.tellurianring.com/projects/gradle-plugins/gradle-templates/apply.groovy'

dependencies {
   groovy localGroovy()
}

//then get a list of tasks:
>> gradle tasks

...
Template tasks
--------------
createGroovyClass - Creates a new Groovy class in the current project. **************
createGroovyProject - Creates a new Gradle Groovy project in a new directory named after your project.
createJavaClass - Creates a new Java class in the current project.
createJavaProject - Creates a new Gradle Java project in a new directory named after your project.
exportGroovyTemplates - Exports the default groovy template files into the current directory.
exportJavaTemplates - Exports the default java template files into the current directory.
initGroovyProject - Initializes a new Gradle Groovy project in the current directory. **************
initJavaProject - Initializes a new Gradle Java project in the current directory.
...


>> gradle initGroovyProject
>> gradle createGroovyClass


/**********************************************************/

//Here's a pretty useful project build.gradle:
apply plugin: 'groovy'
apply from: 'http://www.tellurianring.com/projects/gradle-plugins/gradle-templates/apply.groovy'
apply from: 'http://evgenyg.artifactoryonline.com/evgenyg/libs-releases-local/CodeNarc.gradle'

group = 'myapp1'
mainClassName = 'org.MyCompany.Main'

dependencies {
   groovy localGroovy()
}

jar {
    manifest {
        attributes("Main-Class": mainClassName)
    }
}

// uberjar adds in groovy jars to make this easy: "java -jar MyApp.jar"
task uberjar(type: Jar, dependsOn:[':compileJava', ':compileGroovy']) {
    from files(sourceSets.main.output.classesDir)
    from configurations.runtime.asFileTree.files.collect { zipTree(it) }

    manifest {
        attributes 'Main-Class': mainClassName
    }
}

No comments:

Post a Comment