用Grails中的新版本替换全局库
Grails附带Protobuf 2.4.1作为“全局依赖项”,但我的应用程序使用了一个根据Protobuf 2.5.0编译的库(2.5.0版本与2.4.1不兼容) 问题是,我看不到任何方法可以告诉Grails只使用指定的版本而不是捆绑的版本。如果我在用Grails中的新版本替换全局库,grails,protocol-buffers,Grails,Protocol Buffers,Grails附带Protobuf 2.4.1作为“全局依赖项”,但我的应用程序使用了一个根据Protobuf 2.5.0编译的库(2.5.0版本与2.4.1不兼容) 问题是,我看不到任何方法可以告诉Grails只使用指定的版本而不是捆绑的版本。如果我在BuildConfig中排除它,它只是从应用程序中排除,所有版本都是如此。我的意思是: inherits("global") { excludes 'protobuf-java' } dependencies { //build
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
如何排除全局库,并将其添加为新的依赖项?我使用的是Grails2.2.2您不需要
排除protobuf java
。最新版本作为依赖项提供时,应逐出旧版本。因此v2.4.1将被v2.5.0逐出
inherits("global") {
//excludes 'protobuf-java'
}
dependencies {
build 'com.google.protobuf:protobuf-java:2.5.0'
}
以上应该是好的。为了证明这一点,在grails应用程序上运行一个依赖关系报告
,并查找依赖关系
为了支持事实,我测试了它,它对我非常有效
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@372688e8
遗憾的是,它在我的环境中不起作用:(由于java.lang.VerifyError失败:类…覆盖最终方法getUnknownFields。()Lcom/google/protobuf/UnknownFieldSet;
和依赖关系报告在classpathTrygrails clean和&grails compile
中显示两个版本。ivy报告将同时显示这两个版本,但其中一个应该被逐出。@IgorArtamonov你能给我一个使用v2.5.0特定api的简单片段吗?我也想测试一下。@IgorArtamonov I tried导入MessageOrBuilder
它也没有抱怨我。我希望这对您有用。@dmahapatro您好。我可以知道配置是什么样的吗?因为我面临着与您相同的问题。