使用的是IDEA,直接引入
plugins {
id 'com.github.johnrengelman.shadow' version '1.2.3'
}
放在build.gradle的最上面,然后执行shadowJar即可。
网上说有一种方法
jar {
manifest {
attributes "Main-Class": "$mainClassName"
} from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
这种方法确实打入进去了,但是运行的时候报错,异常如下:
Exception in thread "main" java.lang.VerifyError: (class: org/jboss/netty/channel/socket/nio/NioWorkerPool, method: newWorker signature: (Ljava/util/concurrent/Executor;)Lorg/jboss/netty/channel/socket/nio/AbstractNioWorker;) Wrong return type in function
at org.elasticsearch.transport.netty.NettyTransport.createClientBootstrap(NettyTransport.java:354)
at org.elasticsearch.transport.netty.NettyTransport.doStart(NettyTransport.java:290)
at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:68)
at org.elasticsearch.transport.TransportService.doStart(TransportService.java:182)
at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:68)
at org.elasticsearch.client.transport.TransportClient$Builder.build(TransportClient.java:162)
不知道什么原因,不过用第三方插件暂时可以解决,原因慢慢排查了。
另外还有一种方法可以运行,不过依赖单独放入一个lib目录下,也就是jar和依赖分离的方法:
jar {
String someString = ''
configurations.runtime.each {someString = someString + " lib//"+it.name}
manifest {
attributes 'Main-Class': 'com.gridsum.techpub.legal.etl.App'
attributes 'Class-Path': someString
} }
以后用得到的时候再说~