如何覆盖超级罐中的方法?

时间:2016-09-13 11:58:34

标签: scala cloud google-compute-engine google-cloud-datastore gcloud-java

我正在尝试将此代码用于Google Cloud Datastore:

Query<Entity> query = Query.entityQueryBuilder()
    .kind("Task")
    .filter(PropertyFilter.hasAncestor(
        datastore.newKeyFactory().kind("TaskList").newKey("default")))
    .build();
datastore.run(query, ReadOption.eventualConsistency());

我收到此错误:

  

线程中的异常&#34; main&#34; java.lang.VerifyError:class   com.google.datastore.v1.ReadOptions $ Builder会覆盖final方法   。mergeUnknownFields(LCOM /谷歌/的protobuf / UnknownFieldSet;)LCOM /谷歌/的protobuf / GeneratedMessage $生成器;     at java.lang.ClassLoader.defineClass1(Native Method)at   java.lang.ClassLoader.defineClass(ClassLoader.java:763)at   java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)     在java.net.URLClassLoader.defineClass(URLClassLoader.java:467)at   java.net.URLClassLoader.access $ 100(URLClassLoader.java:73)at   java.net.URLClassLoader $ 1.run(URLClassLoader.java:368)at   java.net.URLClassLoader $ 1.run(URLClassLoader.java:362)at   java.security.AccessController.doPrivileged(Native Method)at   java.net.URLClassLoader.findClass(URLClassLoader.java:361)at   java.lang.ClassLoader.loadClass(ClassLoader.java:424)at   java.lang.ClassLoader.loadClass(ClassLoader.java:357)at   com.google.datastore.v1.ReadOptions.toBuilder(ReadOptions.java:392)     在   com.google.datastore.v1.ReadOptions.newBuilder(ReadOptions.java:386)     在   com.google.cloud.datastore.DatastoreImpl.toReadOptionsPb(DatastoreImpl.java:217)     在   com.google.cloud.datastore.DatastoreImpl.run(DatastoreImpl.java:78)

一些一般细节:

  • 语言:scala
  • 继续:Google计算引擎
  • 使用com.google.guava:guava:19.0和com.google.cloud:google-cloud:0.3.0依赖关系
  • 这是来自google.datastore.v1.protos

    的代码

    public final Builder mergeUnknownFields(         最终com.google.protobuf.UnknownFieldSet unknownFields){       归还这个;     }

  • 这是来自com.google.protobuf.GeneratedMessage的代码

        public BuilderType mergeUnknownFields(UnknownFieldSet unknownFields) {
        this.unknownFields = UnknownFieldSet.newBuilder(this.unknownFields).mergeFrom(unknownFields).build();
        this.onChanged();
        return this;
    }
    

`

2 个答案:

答案 0 :(得分:1)

添加着色依赖项通过使用以下方法解决了spark / google云客户端api冲突问题:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <relocations>
                            <relocation>
                                <pattern>com.google</pattern>
                                <shadedPattern>shaded.com.google</shadedPattern>
                            </relocation>
                        </relocations>
                    </configuration>
                </execution>
            </executions>
        </plugin> 

答案 1 :(得分:0)

我认为这是this issue中所述问题的症状。