解决来自自定义Gradle插件的平台依赖性

问题描述

要编译proto文件,我使用protobuf-gradle-plugin:

plugins {
  id 'com.google.protobuf'
}
...
protobuf {
  protoc {
    artifact = 'com.google.protobuf:protoc:3.12.3'
  }
  plugins {
    grpc {
      artifact = 'io.grpc:protoc-gen-grpc-java:1.30.2'
    }
  }
  generateProtoTasks {
    all()*.plugins {
      grpc {}
    }
  }
}

我想将此设置隐藏在自定义插件中,并从Bom获取protocprotoc-gen-grpc-java坐标:

// bom/build.gradle
plugins {
  id 'java-platform'
}
dependencies {
  constraints {
    api 'io.grpc:protoc-gen-grpc-java:1.30.2'
    api 'com.google.protobuf:protoc:3.12.3'
  }
}
// app/build.gradle
plugins {
  id 'com.google.protobuf'
  id 'my-custom-plugin'
}
...
dependencies {
  compileOnly platform('org.custom.bom:0.1.0-SNAPSHOT')
}

我可以通过gradle API以某种方式获取解析的坐标(com.google.protobuf:protoc:3.12.3io.grpc:protoc-gen-grpc-java:1.30.2)吗?

plugins.withType(ProtobufPlugin.class,protobufPlugin -> {
  project.getConfigurations() ...
  project.getDependencies() ...
  ProtobufConvention protobufConvention = 
    project.getConvention().getPlugin(ProtobufConvention.class);
  ProtobufConfigurator protobuf = protobufConvention.getProtobuf();
  protobuf.protoc(ClosureInterop.of((ExecutableLocator locator) -> 
    locator.setArtifact('...')));
});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...