今日份Rejoiner,今天老大让我弄了个东西,就是在proto文件生成的同时添加一个注释,这个注释可以给前台人员看到,因为rejoiner的文章比较少,所以弄了一上午时间,难受啊,
然后在这里说一下解决过程。
首先说一下解决后的感悟吧,这个东西的执行是这样的:首先在自动生成的时候,直接将proto文件中的注释都添加在一个文件中,然后Regoiner将这些注释在注入进去,这里是自动注入的,所以不用担心,
解决步骤:
1.首先要添加一个生成description文件的依赖
可以用
all().each { task ->
task.plugins {
grpc {
// To generate deprecated interfaces and static bindService method,
// turn the enable_deprecated option to true below:
option 'enable_deprecated=false'
}
}
// If true, will generate a descriptor_set.desc file under
// $generatedFilesBaseDir/$sourceSet. Default is false.
// See --descriptor_set_out in protoc documentation about what it is.
task.generateDescriptorSet = true
// Allows to override the default for the descriptor set location
task.descriptorSetOptions.path =
"${projectDir}/build/descriptors/${task.sourceSet.name}.dsc"
// If true, the descriptor set will contain line number information
// and comments. Default is false.
task.descriptorSetOptions.includeSourceInfo = true
// If true, the descriptor set will contain all transitive imports and
// is therefore self-contained. Default is false.
// task.descriptorSetOptions.includeImports = true
}
也可以使用
ofSourceSet('main').each{task ->
task.generateDescriptorSet = true
task.descriptorSetOptions.includeImports = true
task.descriptorSetOptions.includeSourceInfo = true
task.descriptorSetOptions.path = "${buildDir}/resources/main/META-INF/proto/descriptor_set.desc"
task.plugins {
grpc {}
}
}
然后生成文件后就会产生一个descriptor_set.desc的文件,这个文件中包含所有的注释,然后Rejoiner就会将它自动注入,这样方便前台人员,传参数,写代码,有了注释,方便快捷很多。