当试图创建一个胖罐子时,shadowJar遗漏了很多依赖项。我从工作的pom.xml创建了一个build.gradle文件。 Maven可以毫无问题地构建一个胖子罐。阅读Gradle有关构建胖子的信息,shadowJar插件似乎是推荐的方法。但是,我的Gradle胖罐出现了以下运行时错误:
Jul 19, 2018 2:35:10 PM restclients.RestStatus2Streams writeToStream
SEVERE: Error occurred while instantiating com.me.streams.impl.producer.MarlinProducerV10.
==> java.lang.NoClassDefFoundError: org/apache/hadoop/fs/PathId.
很显然,我的远罐子缺少了一些东西。当然,缺少org / apache / hadoop / fs / PathId和整个依赖项目录。尽管pom.xml没有显式包含'org.apache.hadoop:hadoop-common'依赖关系,但我已将工件作为依赖项显式添加到build.gradle文件中,但仍然没有乐趣。
要回答几个问题:
由于Maven胖子罐工作正常并且解压缩Maven胖子罐显示PathId类(以及Gradle胖子罐中缺少的其他东西),所以我的build.gradle文件和/或shadowJar插件和/或有问题摇篮。
build.gradle 文件:
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'com.github.johnrengelman.shadow'
group = 'com.me.ps'
version = me.version
sourceCompatibility = 1.8
targetCompatibility = 1.8
defaultTasks 'shadowJar'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.3'
}
}
repositories {
[...]
}
dependencies {
// Explicityly added to in hopes of being included in the fat jar
compile group: 'org.apache.hadoop', name: 'hadoop-common', version: '2.7.0-me-1803'
// dependencies listed in the pom.xml
compile group: 'com.me.ojai', name: 'me-ojai-driver', version: '6.0.1-me'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.6.5'
compile group: 'org.apache.kafka', name: 'connect-json', version: '1.0.1-me-1803-streams-6.0.1'
compile group: 'org.apache.spark', name: 'spark-core_2.11', version: '2.2.1'
compile group: 'org.apache.spark', name: 'spark-streaming_2.11', version: '2.2.1-me-1803'
compile group: 'org.apache.spark', name: 'spark-streaming-kafka-0-10_2.11', version: '2.2.1-me-1803'
compile group: 'org.apache.kafka', name: 'kafka-clients', version: '1.0.1-me-1803-streams-6.0.1'
// dependencies not in the pom.xml, but added to make the gradle build work
compile group: 'xerces', name: 'xercesImpl', version: '2.11.0'
compile group: 'org.json', name: 'json', version: '20171018'
compile group: 'com.google.guava', name: 'guava', version: '19.0'
}
shadowJar {
zip64 true
baseName 'me-edge'
}
我的build.gradle文件做什么错了?