Maven 使Storm JAR只在Gradle项目中编译

Maven 使Storm JAR只在Gradle项目中编译,maven,gradle,apache-storm,Maven,Gradle,Apache Storm,我正在尝试建立一个Gradle项目,其中包含一个Storm项目。为了在Storm上运行这个项目,我必须首先创建一个JAR文件并让Storm运行我的拓扑,例如 storm jar myJarFile.jar com.mypackage.MyStormMainClass 我遇到了问题,因为Gradle默认在编译时和运行时都包含了Storm依赖项。这会导致以下异常: Exception in thread "main" java.lang.RuntimeException: Found multip

我正在尝试建立一个Gradle项目,其中包含一个Storm项目。为了在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上的其他帖子没有解决这个问题。如果粘贴代码,请确保它实际运行

谢谢

下面我引用了一个例子

在我的例子中,我选择使用for 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
        }
    }
}
您可以通过以下方式构建胖罐:

$ gradle clean fatJar
最好的, 迈克尔


PS:值得一提的是,我还写了一篇关于如何解决上述问题的博客。这篇文章包含了一些对你可能有帮助,也可能没有帮助的信息和窍门。

+1在你的博客上写下精彩的文章。你知道可以排除哪些其他罐子吗?我很想减少我的脂肪罐,因为它现在看起来有点太胖了……到目前为止,我只排除了Storm依赖项本身,因此根据我自己的实际经验,我无法建议您排除其他DEP是否安全。让我们知道您的问题是否已得到回答。