# Fat / shadow / uber jar with groovy scripts included

**URL:** <https://discuss.gradle.org/t/fat-shadow-uber-jar-with-groovy-scripts-included/26658>\
**Category:** Help/Discuss\
**Created:** [April 18, 2018, 10:58am UTC](https://discuss.gradle.org/t/fat-shadow-uber-jar-with-groovy-scripts-included/26658 "2018-04-18T10:58:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![obesga-tirant](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@obesga-tirant](https://discuss.gradle.org/u/obesga-tirant)\
**Post date:** [April 18, 2018, 10:58am UTC](https://discuss.gradle.org/t/fat-shadow-uber-jar-with-groovy-scripts-included/26658/1 "2018-04-18T10:58:33Z")

</div>

Hi all

I’ve tried to make a fat jar with the groovy scripts (in source code) from the dir `src/main/scripts` into the jar (at the root of the jar).

But I’ve tried many configurations, no one seems to work 😞

I want to include all the groovy and sql,mongo,etc. dependencies into this fat jar to execute the groovy scripts with one java call,  
because in my server groovy is not installed.  
Like this  
⏩ `java -cp helmeplease-all-1.0.jar groovy.ui.GroovyMain jar:file:helmeplease-all-1.0.jar'!'/thankyou.groovy`

:gradlephant: My current **build.gradle** is here

```
group 'helmeplease'
version '1.0'

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'maven'

sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
    mavenCentral()
    mavenLocal()
    // ...
}

dependencies {
    compile group:'mysql', name:'mysql-connector-java', version:'5.1.46'
    compile 'commons-dbcp:commons-dbcp:1.4'
    compile group:'org.mongodb', name:'mongo-java-driver', version:'2.11.3'
    compile 'org.codehaus.groovy:groovy-all:2.1.9'
    compile group:'com.gmongo', name:'gmongo', version:'1.3'
}

jar {
    manifest {
        attributes 'Implementation-Title': 'lopd_importer', 'Implementation-Version': version
    }
}

task fatJar(type: Jar) {
    dependsOn install
    manifest {
        attributes 'Manifest-Version': '1.0', 'Implementation-Title': 'gd-web-lexnet-firma-client', 'Implementation-Version': version
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

```

I’ve tried with

`sourceSets.main.resources.srcDirs += ["src/main/scripts"]`

Also with

```
task fatJar(type: Jar) {
    // ...
    from('src/main/scripts) {
        include '**/*.groovy'
    }
    //...
}

```

And many more variations, but it seems I can’t hit the nail 😖

Anyone knows how to make it ?  
Thanks 🙂

---

<div class="post-metadata">

**Author:** ![obesga-tirant](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@obesga-tirant](https://discuss.gradle.org/u/obesga-tirant)\
**Post date:** [April 18, 2018, 12:52pm UTC](https://discuss.gradle.org/t/fat-shadow-uber-jar-with-groovy-scripts-included/26658/2 "2018-04-18T12:52:44Z")

</div>

Hi again!

I think I was without the needed coffe when I tried this 😓

Because I tried again, and now it works  
With the code  
`sourceSets.main.resources.srcDirs += ["src/main/scripts"]`  
finally worked !! 😊

Grapes wont work (event including ivy in gradle dependencies), this error is thrown  
`General error during conversion: No suitable ClassLoader found for grab - java.lang.RuntimeException: No suitable ClassLoader found for grab`

But as you can include all dependencies into **build.gradle** , you’re ok

Final **build.gradle** version

```
group 'helmeplease'
version '1.0'

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'maven'

sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
    mavenCentral()
    mavenLocal()
    // ...
}

dependencies {
    compile group:'mysql', name:'mysql-connector-java', version:'5.1.46'
    compile 'commons-dbcp:commons-dbcp:1.4'
    compile group:'org.mongodb', name:'mongo-java-driver', version:'2.11.3'
    compile 'org.codehaus.groovy:groovy-all:2.1.9'
    compile group:'com.gmongo', name:'gmongo', version:'1.3'
}

sourceSets.main.resources.srcDirs += ["src/main/scripts"]

jar {
    manifest {
        attributes 'Implementation-Title': 'lopd_importer', 'Implementation-Version': version
    }
}

task fatJar(type: Jar) {
    dependsOn install
    manifest {
        attributes 'Manifest-Version': '1.0', 'Implementation-Title': 'gd-web-lexnet-firma-client', 'Implementation-Version': version
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

```

You can execute it with

`java -cp helmeplease-all-1.0.jar groovy.ui.GroovyMain jar:file:helmeplease-all-1.0.jar'!'/thankyou.groovy`

Or if you want your script external, just execute

`java -cp helmeplease-all-1.0.jar groovy.ui.GroovyMain ./thankyou.groovy`

I don’t know if there’s a more elegant solution, but this works fine

Thanks and sorry for the incovenience
