Java 如何使用Groovy为胖JAR指定运行时依赖项

Java 如何使用Groovy为胖JAR指定运行时依赖项,java,groovy,jar,executable-jar,jitpack,Java,Groovy,Jar,Executable Jar,Jitpack,非常简短的搜索: 具有所需的输出。然而,建议的解决方案,一个“脂肪罐”,导致了这个怪物: 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/ ne

非常简短的搜索:

具有所需的输出。然而,建议的解决方案,一个“脂肪罐”,导致了这个怪物:

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
这一切似乎无休无止地继续下去。显然,我不想把groovy包括在胖罐子里。如何从构建的JAR中排除groovy

生成文件:

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'
}
有哪些替代方案:

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

诚然,我还没有学会Groovy DSL,到目前为止我只是在拼凑一些零碎的东西


我相信我看到有人提到从一组依赖项中减去另一组依赖项以最小化包含的库。然而,在奇怪的情况下,有些库不需要编译,但需要执行JAR,我不确定这将如何工作。

那么是什么让groovy进来的呢?你试过gradle的shadow插件吗?我不确定groovy到底在做什么。我真的不想要一个“胖罐子”,我想,也不想要一个影子罐子。只是一个“瘦罐子”,只有我的客户端代码。有关类似的问题,请参见。
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'
}