1

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

4

1 回答 1

2

你不需要exclude protobuf-java。最新版本作为依赖项提供时,应驱逐旧版本。所以 v2.4.1 将被 v2.5.0 驱逐。

inherits("global") {
    //excludes 'protobuf-java'
}

dependencies {
    build 'com.google.protobuf:protobuf-java:2.5.0'
}

以上应该不错。为了见证这一点,dependency-report在 grails 应用程序上运行 a 并查找依赖项。

为了支持事实,我对其进行了测试,它对我来说非常有效。

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
于 2013-06-06T14:53:10.250 回答