-1

I'm struggling to configure a super simple (my 1st ever) Gradle buildscript, that will:

  1. Compile all the Groovy code under my src/main/groovy dir; compilation needs to include all the local (not from a repo) JARs stored in my lib/ directory
  2. Place that compiled code under /bin (or wherever, I really don't care)
  3. JAR up the compiled code into myapp.jar
  4. Somehow include the wrapper task so that the gradlew gets generated as is appropriate

My project dir structure:

myapp/
    src/main/groovy/
        <Groovy sources>
    bin/
    lib/
        <lots of JARs>
    build.gradle
    gradle.properties

So far this is what I've tried:

apply groovy
task compile {
    println "Compiling from src/main/groovy and lib/ to bin/"
    javac ???
}
task jar {
    println "JARring up the code"
    jar ???
}

Any help or nudges in the right direction would be enormously helpful for me.

IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756

1 Answers1

1

What You need to do is just to apply plugin: 'groovy' and add the following section:

dependencies {
    compile fileTree(dir: 'lib', include: '*.jar')
}
Opal
  • 81,889
  • 28
  • 189
  • 210
  • Thanks @Opal (+1!) - But where would I specify the name of my JAR to build? Also, what about the `wrapper` task? – IAmYourFaja Aug 07 '14 at 13:12
  • Here's DSL for Jar task: http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.bundling.Jar.html. Look for `archiveName`. You can specify it with jar { archiveName = 'MyArchive'} – Opal Aug 07 '14 at 13:16
  • 1
    When it comes to wrapper - just read about it: http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.bundling.Jar.html. Basically it's a script that downloads gradle (for specified) version and use this downloaded instance to run the scripts. – Opal Aug 07 '14 at 13:20
  • Thanks @Opal (+2) - so can you just confirm that added a `wrapper` task is not common in a Gradle buildscript? If so, how often do you run the script manually from the shell? Thanks again! – IAmYourFaja Aug 07 '14 at 14:32
  • 1
    `wrapper` task is added by default to every `build.gradle` script. If ensures that all users that are working with project will be using same version of gradle (it can be configured). If wrapper isn't used then You can just install gradle (unzip) and add to $PATH to build the projects. – Opal Aug 07 '14 at 14:36
  • Ahh, I see @Olap (+1) - it is added to all scripts by default, but you can generate it from an explicit version if you want it to (`gradleVersion = '1.11'`, etc.) by including a `task wrapper(type: Wrapper`) task to your build, yes? – IAmYourFaja Aug 07 '14 at 14:39