use of org.curioswitch.gradle.protobuf.ProtobufExtension in project curiostack by curioswitch.
the class GrpcApiPlugin method apply.
@Override
public void apply(Project project) {
project.getRootProject().getPlugins().apply(GrpcApiSetupPlugin.class);
project.getPlugins().apply(JavaLibraryPlugin.class);
project.getPlugins().apply(ProtobufPlugin.class);
project.getPlugins().apply(NodePlugin.class);
var config = GrpcExtension.createAndAdd(project);
GRPC_DEPENDENCIES.forEach(dep -> project.getDependencies().add("api", "io.grpc:" + dep));
ProtobufExtension protobuf = project.getExtensions().getByType(ProtobufExtension.class);
protobuf.getProtoc().getArtifact().set("com.google.protobuf:protoc");
protobuf.getLanguages().register("grpc", language -> language.getPlugin().getArtifact().set("io.grpc:protoc-gen-grpc-java"));
project.afterEvaluate(p -> {
String archivesBaseName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName();
var descriptorOptions = protobuf.getDescriptorSetOptions();
descriptorOptions.getPath().set(project.file("build/resources/main/META-INF/armeria/grpc/" + project.getGroup() + "." + archivesBaseName + ".dsc"));
descriptorOptions.getEnabled().set(true);
descriptorOptions.getIncludeSourceInfo().set(true);
descriptorOptions.getIncludeImports().set(true);
if (config.getWeb().get()) {
protobuf.getLanguages().register("js", language -> {
language.option("import_style=commonjs,binary");
language.getOutputDir().set(project.file("build/webprotos"));
});
protobuf.getLanguages().register("grpc-web", language -> {
language.getPlugin().getPath().set(project.file(DownloadedToolManager.get(project).getToolDir("protoc-gen-grpc-web").resolve("protoc-gen-grpc-web" + (IS_WINDOWS ? ".exe" : ""))));
language.option("import_style=commonjs+dts");
language.option("mode=grpcweb");
language.getOutputDir().set(project.file("build/webprotos"));
});
project.getTasks().withType(GenerateProtoTask.class).configureEach(t -> t.execOverride(exec -> DownloadedToolManager.get(project).addAllToPath(exec)));
}
});
// Additional configuration of tasks created by protobuf plugin.
project.afterEvaluate(p -> {
if (config.getWeb().get()) {
var installProtocGenGrpcWeb = DownloadToolUtil.getSetupTask(project, "protoc-gen-grpc-web");
var generateProto = project.getTasks().named("generateProto");
var packageWeb = project.getTasks().register("packageWeb", PackageWebTask.class, t -> {
t.dependsOn(generateProto);
t.getWebPackageName().set(config.getWebPackageName());
t.getPackageJsonTemplate().set(PACKAGE_JSON_TEMPLATE);
});
generateProto.configure(t -> t.dependsOn(installProtocGenGrpcWeb).finalizedBy(packageWeb));
project.getRootProject().getTasks().named("yarn").configure(t -> t.dependsOn(generateProto));
// Unclear why sometimes compileTestJava fails with "no source files" instead of being
// skipped (usually when activating web), but it's not that hard to at least check the
// source set directory.
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
if (sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME).getAllJava().isEmpty()) {
project.getTasks().named("compileTestJava").configure(t -> t.setEnabled(false));
project.getTasks().named("test").configure(t -> t.setEnabled(false));
}
}
});
}
Aggregations