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

我正在尝试将此代码用于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());

我收到此错误:

线程“main”中的异常java.lang.VerifyError:class com.google.datastore.v1.ReadOptions $ Builder重写final方法mergeUnknownFields . (Lcom / google / protobuf / UnknownFieldSet;)Lcom / google / protobuf / GeneratedMessage $ Builder;位于java.lang.ClassLoader.defineClass1(Native Method)的java.security.ClassLoader.defineClass(ClassLoader.java:763),位于java.net.URLClassLoader.defineClass的java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) (URLClassLoader.java:467)java.net.URLClassLoader.access $ 100(URLClassLoader.java:73)java.net.URLClassLoader $ 1.run(URLClassLoader.java:368)java.net.URLClassLoader $ 1.run(URLClassLoader) .java:362)java的java.security.AccessController.doPrivileged(Native Method),java.net.URLClassLoader.findClass(URLClassLoader.java:361),java.lang.ClassLoader.loadClass(ClassLoader.java:424) . com.google.datastore.v1.ReadOptions.newBuilder的com.google.datastore.v1.ReadOptions.toBuilder(ReadOptions.java:392)中的lang.ClassLoader.loadClass(ClassLoader.java:357)(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(final com.google.protobuf.UnknownFieldSet unknownFields){return this; }

  • 这是com.google.protobuf.GeneratedMessage中的代码
public BuilderType mergeUnknownFields(UnknownFieldSet unknownFields) {
    this.unknownFields = UnknownFieldSet.newBuilder(this.unknownFields).mergeFrom(unknownFields).build();
    this.onChanged();
    return this;
}

`

回答(2)

2 years ago

添加着色依赖项通过使用以下方法解决了spark / google Cloud 客户端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>

2 years ago

我相信这是this issue中描述的问题的症状 .