Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Grails中的新版本替换全局库_Grails_Protocol Buffers - Fatal编程技术网

用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

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

如何排除全局库,并将其添加为新的依赖项?我使用的是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;
和依赖关系报告在classpathTry
grails clean和&grails compile
中显示两个版本。ivy报告将同时显示这两个版本,但其中一个应该被逐出。@IgorArtamonov你能给我一个使用v2.5.0特定api的简单片段吗?我也想测试一下。@IgorArtamonov I tried导入
MessageOrBuilder
它也没有抱怨我。我希望这对您有用。@dmahapatro您好。我可以知道配置是什么样的吗?因为我面临着与您相同的问题。