Protobuf 编组器在使用 Gradle 时未注册?

Protobuf marshallers not registering when using Gradle?

我有一个项目,我试图让 protobuf 与 infinispan、quarkus 和 gradle 一起工作。问题是,尽管我按照 Quarkus 主页中给出的说明进行操作:https://quarkus.io/guides/infinispan-client,但似乎当我使用 gradle 时,编组器并未按应有的方式生成和注册。在我看来,这似乎归结为 org.infinispan.protostream:protostream-processor 在 gradle 是构建工具时未执行。这是一个有意识的决定,只支持 Maven,还是我在 gradle 设置中遗漏了一些明显的东西?

可在此处找到最简单案例的复制:https://github.com/radiosphere/gradle-java-protobuf for gradle and here for maven: https://github.com/radiosphere/mvn-java-protobuf。这些项目非常基础,基本上是尝试 运行 启动时的简单代码:

    public void onStartup(@Observes StartupEvent startupEvent) {
        RemoteCache<String, CounterState> cache = cacheManager.administration().getOrCreateCache("default", DefaultTemplate.DIST_SYNC);

        cache.put("a", new CounterState(2L));
        CounterState state = cache.get("a");

        logger.infof("State: %s", state);
    }

在 maven 项目中这有效,在 gradle 项目中抛出异常,提示找不到编组器。除了构建工具的选择外,项目应该是相同的。

注释处理器在 Maven 构建中运行,因为 io.quarkus:quarkus-infinispan-clientorg.infinispan.protostream:protostream-processor 具有 compile 依赖性。

看起来像 Gradle made a decision to not use annotation processors found in the compile classpath:

Since implementation details matter for annotation processors, they must be declared separately on the annotation processor path. Gradle ignores annotation processors on the compile classpath.

这意味着您必须添加显式 annotationProcessor 依赖项:

    annotationProcessor 'org.infinispan.protostream:protostream-processor:4.4.0.Final'