使用的是IDEA,直接引入java
plugins { id 'com.github.johnrengelman.shadow' version '1.2.3' }
放在build.gradle的最上面,而後執行shadowJar便可。git
網上說有一種方法github
jar { manifest { attributes "Main-Class": "$mainClassName" } from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } }
這種方法確實打入進去了,可是運行的時候報錯,異常以下:socket
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)
不知道什麼緣由,不過用第三方插件暫時能夠解決,緣由慢慢排查了。elasticsearch
另外還有一種方法能夠運行,不過依賴單獨放入一個lib目錄下,也就是jar和依賴分離的方法:gradle
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 } }
之後用獲得的時候再說~ui