我正在尝试构建一个包含Storm项目的Gradle项目。为了在Storm上运行此项目,我必须首先创建一个JAR文件,然后让Storm运行我的拓扑,例如
storm jar myJarFile.jar com.mypackage.MyStormMainClass
我遇到了问题,因为默认情况下,Gradle在编译时和运行时都包括Storm依赖项。这将导致以下异常:
Exception in thread "main" java.lang.RuntimeException: Found multiple defaults.yaml resources. You're probably bundling the Storm jars with your topology jar.
给出的异常实际上是有帮助的,它使我们了解问题的根本原因。解决方案是在使用Gradle编译时包括Storm依赖项,但在生成最终的JAR文件时不包括。
有谁知道如何解决这个问题? StackOverflow上的其他帖子没有解决问题。如果粘贴代码,请确保其实际运行。
谢谢!
最佳答案
在下面,我将an answer of mine引用为similar thread on the storm-user mailing list。
就我而言,我选择将fatJar plugin用于Gradle来实现此目的。
buildscript {
repositories {
mavenCentral()
mavenRepo url: "http://clojars.org/repo"
}
dependencies {
// see https://github.com/musketyr/gradle-fatjar-plugin
classpath 'eu.appsatori:gradle-fatjar-plugin:0.2-rc1'
}
}
// When using this plugin you can build a fat jar / uberjar with 'gradle fatJar'
apply plugin: 'fatjar'
dependencies {
compile 'storm:storm:0.8.2', {
ext {
fatJarExclude = true
}
}
}
您可以通过以下方式建立 fat jar :
$ gradle clean fatJar
最好的,
麦可
PS:值得的是,我还在Running a Multi-Node Storm Cluster上写了关于如何解决此问题的博客。该帖子包含可能对您有所帮助或可能没有帮助的其他信息和陷阱。
关于maven - 仅在Gradle项目中使Storm JAR编译时,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17421726/