使 Storm JAR 仅在 Gradle 项目中编译 [英] Making the Storm JARs compile-time only in a Gradle project

查看:23
本文介绍了使 Storm JAR 仅在 Gradle 项目中编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个包含 Storm 项目的 Gradle 项目.为了在 Storm 上运行这个项目,我必须首先创建一个 JAR 文件并让 Storm 运行我的拓扑,例如

I am trying to build a Gradle project which contains a Storm project. In order to run this project on Storm, I have to first create a JAR file and let Storm run my topology, e.g.

storm jar myJarFile.jar com.mypackage.MyStormMainClass

我遇到了问题,因为 Gradle 默认在编译时和运行时都包含 Storm 依赖项.这会导致以下异常:

I am running into problems because Gradle, by default, is including the Storm dependencies both at compile time and runtime. This causes the following exception:

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 文件时不包含.

The Exception given is actually helpful, and tips us off to the root cause of the problem. The solution is to include the Storm dependencies when compiling with Gradle, but not when generating the final JAR file.

有谁知道如何解决这个问题?StackOverflow 上的其他帖子没有解决问题.如果您粘贴代码,请确保它实际运行.

Does anyone know how to resolve this? The other posts on StackOverflow did not solve the problem. If you paste code please ensure that it actually runs.

谢谢!

推荐答案

下面我引用了 我对 rel="nofollow">storm-user 邮件列表上的类似帖子.

Below I am quoting an answer of mine to a similar thread on the storm-user mailing list.

就我而言,为此我选择使用 Gradle 的 fatJar 插件.

In my case I opted to use the fatJar plugin for Gradle for that purpose.

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
        }
    }
}

您通过以下方式构建胖罐:

You build the fat jar via:

$ gradle clean fatJar

最好的,迈克尔

PS:我还在运行多节点风暴集群.该帖子包含其他信息和陷阱,可能对您有帮助,也可能无济于事.

PS: For what it's worth I also blogged about how to solve this problem as described above at Running a Multi-Node Storm Cluster. That post contains additional pieces of information and gotchas that may or may not be helpful to you.

这篇关于使 Storm JAR 仅在 Gradle 项目中编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆