Skip to content

Instantly share code, notes, and snippets.

@weitzj
Created January 9, 2012 00:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weitzj/1580234 to your computer and use it in GitHub Desktop.
Save weitzj/1580234 to your computer and use it in GitHub Desktop.
groovy, java, intellij IDEA setup
/**
* Initial build.gradle script to wrap groovy/java scripts into one fat jar file.
* (including some nice tools for scripting: GROOVY, GPARS, LOG4J, ANTBUILDER, CLI-PARSER)
*
* Project Setup via:
* gradle makeDirs
*
*
* IntelliJ IDEA integration:
* gradle idea
* [
* Note on IntelliJ IDEA 11:
* 1. run the 'gradle idea' task
* 2. open the project by opening the generated '*.ipr' file (and not the project folder)
* (so that the new Gradle Integration in IDEA 11 does not recognize the build.gradle
* file automatically and messes up the gradle-generated idea project files)
* [ The dependency integration works very well using the gradle 'idea' plugin. If you
* introduce more dependencies, run the 'gradle idea' task again ]
* ]
*
*
* 'mainClassName' should be either
* a Groovy SCRIPT with the SAME FILE-Name and package
* or
* a Groovy CLASS with the SAME Name and package
*
*
* Create one fat jar:
* gradle assemble
*
* [Notes: be aware that you can get in trouble if you use signed jars] You can use the application
* plugin to ship the signed jars separately.
* ]
*/
apply plugin:'application'
apply plugin:'idea'
apply plugin:'groovy'
mainClassName = 'org.example.MainClass'
version = '1.0'
description = '''This is the main description'''
idea {
project {
//if you want to set specific jdk and language level
jdkName = '1.6'
languageLevel = '1.6'
//download docs, if they can be found
module {
downloadJavadoc = true
}
}
}
repositories {
//include lib folder
flatDir { dirs 'lib' }
mavenCentral()
}
//cross compilation for Java Classes.
//http://gradle.1045684.n5.nabble.com/Groovy-Java-mixed-codebase-td1435484.html
sourceSets {
main {
java { srcDirs = [] }
groovy { srcDir 'src' }
}
}
dependencies {
//groovy 1.8.5
//groovy 'org.codehaus.groovy:groovy-all:1.8.5'
//groovy 2.0.0-beta-2
groovy 'org.codehaus.groovy:groovy:2.0.0-beta-2'
//groovy-all does not contain every jar the normal
//groovy distribution includes. So we add them manually.
//general
compile 'log4j:log4j:1.2.16' //logging
compile 'log4j:apache-log4j-extras:1.1' //logging extras
compile 'org.apache.ant:ant:1.8.2' //antbuilder
compile 'org.codehaus.gpars:gpars:0.12' //gpars
compile 'commons-cli:commons-cli:1.2' //command line parser
//add all jars from lib-folder
compile fileTree (dir: 'lib', includes: ['*.jar'])
}
jar {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes (
'Main-Class': mainClassName
)
}
}
task makeDirs(description:'make all dirs for project setup') << {
def sources = [sourceSets.main, sourceSets.test]
sources*.allSource*.srcDirs.flatten().each { File srcDir ->
println "making $srcDir"
srcDir.mkdirs()
}
}
task wrap(type:Wrapper, description:"create a gradlew") {
gradleVersion = '1.0-milestone-6'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment