0

A very brief search explained to how to package run time dependencies for distribution:

thufir@mordor:~/NetBeansProjects/hello_client$ 
thufir@mordor:~/NetBeansProjects/hello_client$ gradle clean build
Changed strategy of configuration ':compile' after it has been resolved. This behaviour has been deprecated and is scheduled to be removed in Gradle 3.0
:clean
:compileJava
:processResources UP-TO-DATE
:classes
:jar
:startScripts
:distTar
:distZip
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build

BUILD SUCCESSFUL

Total time: 9.237 secs
thufir@mordor:~/NetBeansProjects/hello_client$ 
thufir@mordor:~/NetBeansProjects/hello_client$ java -jar build/libs/hello_client.jar
hello [fred]
thufir@mordor:~/NetBeansProjects/hello_client$ 

with the desired output. However, the suggested solution, a "fat jar", results in this monstrosity:

thufir@mordor:~/NetBeansProjects/hello_client$ 
thufir@mordor:~/NetBeansProjects/hello_client$ jar -ft build/libs/hello_client.jar 
META-INF/
META-INF/MANIFEST.MF
net/
net/bounceme/
net/bounceme/mordor/
net/bounceme/mordor/hello/
net/bounceme/mordor/hello/client/
net/bounceme/mordor/hello/client/HelloClient.class
net/bounceme/mordor/hello/library/
net/bounceme/mordor/hello/library/HelloLibrary.class
META-INF/ANTLR-LICENSE.txt
META-INF/ASM-LICENSE.txt
META-INF/CLI-LICENSE.txt
META-INF/JSR223-LICENSE.txt
META-INF/LICENSE.txt
META-INF/NOTICE.txt
META-INF/dgminfo
META-INF/groovy-release-info.properties
META-INF/maven/
META-INF/maven/commons-cli/
META-INF/maven/commons-cli/commons-cli/
META-INF/maven/commons-cli/commons-cli/pom.properties
META-INF/maven/commons-cli/commons-cli/pom.xml
META-INF/services/
META-INF/services/javax.script.ScriptEngineFactory
META-INF/services/org.codehaus.groovy.plugins.Runners
META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
META-INF/services/org.codehaus.groovy.source.Extensions
META-INF/services/org.codehaus.groovy.transform.ASTTransformation
groovy/
groovy/beans/
groovy/beans/Bindable.class
groovy/beans/BindableASTTransformation.class

which then goes on seemingly endlessly. Obviously, I don't want to include groovy in the fat jar. How can I exclude groovy from the built JAR?

build file:

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'maven'

mainClassName = 'net.bounceme.mordor.hello.client.HelloClient'

sourceCompatibility = '1.8'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
if (!hasProperty(mainClassName)) {
    ext.mainClass = mainClassName
}

repositories {
    mavenCentral()
    maven { url "https://jitpack.io" }
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.10'
    compile 'com.github.THUFIR:hello_api:dev'
}

jar {

    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    manifest {
        attributes ('Main-Class': mainClassName,
            "Class-Path": configurations.compile.collect { it.getName() }.join(' '))
    }
}

assemble.dependsOn (jar)

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

what alternatives are there to:

from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }

Admittedly, I haven't learned the Groovy DSL and am just kludging together bits and pieces so far.

I believe that I saw mention of subtracting one set of dependencies from another to minimize the included libraries. However, in the odd case that there are libraries which aren't required to compile, but are required to execute the JAR, I'm not sure how that would work.

Thufir
  • 8,216
  • 28
  • 125
  • 273
  • So what's pulling groovy in? Have you tried the shadow plugin for gradle? – tim_yates Mar 12 '16 at 11:05
  • I'm not sure what's pulling in groovy. I don't really want a "fat jar", nor, I think, a shadow jar. Just a "slim jar", only my client code. see also http://stackoverflow.com/questions/13982395/how-to-exclude-files-from-distzip-using-gradle for a similar question. – Thufir Mar 14 '16 at 03:36

0 Answers0