【问题标题】:Replace a global library with a new version in Grails在 Grails 中用新版本替换全局库
【发布时间】:2013-06-02 03:09:43
【问题描述】:

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

【问题讨论】:

    标签: grails protocol-buffers


    【解决方案1】:

    你不需要excludeprotobuf-java。最新版本作为依赖项提供时,应驱逐旧版本。所以 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@372688e8
    

    【讨论】:

    • 很遗憾,但它不适用于我的环境 :( 失败并出现 java.lang.VerifyError: class ... overrides final method getUnknownFields.()Lcom/google/protobuf/UnknownFieldSet; 并且依赖项报告在类路径中显示两个版本
    • 试试grails clean && grails compile。常春藤报告会显示两者,但应该驱逐一个。
    • @IgorArtamonov 你能给我一个简单的sn-p,它使用v2.5.0特有的api吗?我也想测试一下。
    • @IgorArtamonov 我尝试导入 MessageOrBuilder 它也没有抱怨我。我希望这对你有用。
    • @dmahapatro 你好。可以知道是什么配置吗?因为我和你面临同样的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-04
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多