Grails附带了Protobuf 2.4.1作为“全局依赖”,但我的应用程序使用了一个针对Protobuf 2.5.0编译的库( 2.5.0版本与2.4.1不兼容)。
问题是,我看不到任何方法来告诉Grails只使用指定的版本而不是捆绑的。如果我在BuildConfig中排除它,它只是从应用程序中排除,所有版本。我的意思是:
inherits("global") {
excludes 'protobuf-java'
}
dependencies {
//build 'com.google.protobuf:protobuf-java:2.5.0'
// or
compile 'com.google.protobuf:protobuf-java:2.5.0'
}Grails失败,并显示以下错误:
Fatal error during compilation org.apache.tools.ant.BuildException:
java.lang.NoClassDefFoundError: com/google/protobuf/MessageOrBuilder如何排除全局库,并将其添加为新的依赖项?我使用的是Grails 2.2.2
发布于 2013-06-06 22:53:10
您无需对protobuf-java执行exclude操作。最新的版本,当作为依赖项提供时,应该驱逐旧版本的。因此v2.4.1将被v2.5.0逐出。
inherits("global") {
//excludes 'protobuf-java'
}
dependencies {
build 'com.google.protobuf:protobuf-java:2.5.0'
}上面的内容应该是好的。要证明这一点,请在grails应用程序上运行dependency-report并查找依赖项。
为了支持事实,我对它进行了测试,它对我来说是完美的。
import com.google.protobuf.TextFormat
//Just to replicate your issue, but it did not complain about this import.
import com.google.protobuf.MessageOrBuilder
class BootStrap {
def init = { servletContext ->
TextFormat t = new TextFormat()
println t
}
def destroy = {
}
}
//Prints:
com.google.protobuf.TextFormat@372688e8https://stackoverflow.com/questions/16956505
复制相似问题