gpt4 book ai didi

grails - 在Grails中用新版本替换全局库

转载 作者:行者123 更新时间:2023-12-02 14:34:38 25 4
gpt4 key购买 nike

Grails随附Protobuf 2.4.1作为“全局依赖项”,但我的应用程序使用针对Protobuf 2.5.0编译的库(而2.5.0版与2.4.1不兼容)。

我看不出有任何办法告诉Grails仅使用指定版本而不是 bundle 包的问题。如果我将其排除在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

最佳答案

您不需要exclude protobuf-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

关于grails - 在Grails中用新版本替换全局库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16956505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com