I'm trying to get an executable JAR that contains groovy code that I can run
by doing a simple: java -jar myapp.jar

Here's my build.gradle

usePlugin 'groovy'
usePlugin 'maven'  // Maven plugin to install artifact in local Maven repo.

sourceCompatibility = '1.6'
targetCompatibility = '1.6'

manifest.mainAttributes("Main-Class" : "org.mindscratch.foo.ParseMain")

def localMavenRepo = 'file://' + new File(System.getProperty('user.home'),
'.m2/repository').absolutePath
repositories {
    // Use local Maven repo location. We don't need this if we only want to
install
    // an artifact, but we do need it if we want to use dependencies from
the local
    // repository.
    mavenRepo urls: localMavenRepo
}

// Project configuration:
version = '1.0-SNAPSHOT'
group = 'org.mindscratch.foo'

// The following line is not necessary. Default the install tasks depends on
the
// jar task, but this means no tests and checks are executed when we use the
// install task. The following line makes the install tasks depend on the
build task
// and now all tests and checks are done before install is executed.
install.dependsOn ':build'


repositories {
    mavenCentral()  // Define Maven central repository to look for
dependencies.
}

dependencies {
    groovy 'org.codehaus.groovy:groovy:1.6.7'  // group:name:version is a
nice shortcut notation for dependencies.
    testCompile 'junit:junit:4.7'
}


task initProject(description: 'Initialize project directory structure.') <<
{
    // Default package to be created in each src dir.
    def defaultPackage = 'org/mindscratch/foo'

    ['java', 'groovy', 'resources'].each {
        // convention.sourceSets contains the directory structure
        // for our Groovy project. So we use this struture
        // and make a directory for each node.
        convention.sourceSets.all."${it}".srcDirs*.each { dir ->
            def newDir = new File(dir, defaultPackage)
            logger.info "Creating directory $newDir"  // gradle -i shows
this message.
            newDir.mkdirs()  // Create dir.
        }
    }
}


I run:
$ gradle install -i
$ cd build/libs
$ java -jar foo-1.0-SNAPSHOT.jar

..doesn't work b/c the Groovy jar isn't on the classpath (or inside my JAR).
 GUess what I need is a JAR that contians the Groovy jar inside of it (maybe
in a "lib" folder).  Can you help?

thanks

Reply via email to