同时使用Lombok和Protobuf会导致无依赖性的Gradle任务,导致构建失败有时
我在Gradle中同时使用Lombok和Protobuf。这将生成任务generateFectivectivelectivelectivelombokconfig
和generateProto
是独立的。然而,Lombok任务应取决于Protobuf任务,否则Lombok生成的代码指的是尚未由Protoc生成的Java代码。
syntax = "proto3";
package my.example.v1;
message Task {
string id = 1;
repeated string names_to_print = 2;
}
package org.example;
import lombok.experimental.UtilityClass;
import my.example.v1.*;
@UtilityClass
public class Worker {
public void work(TaskOuterClass.Task task) {
// do something
}
}
plugins {
id 'java'
id 'io.freefair.lombok' version '6.4.3'
id 'com.google.protobuf' version '0.8.18'
}
group 'org.example'
repositories {
mavenCentral()
}
dependencies {
implementation "com.google.protobuf:protobuf-java:3.20.1"
implementation "com.google.protobuf:protobuf-java-util:3.20.1"
}
我试图将Protobuf的输出添加为源,以确保首先执行ProtoBuf任务,但我会收到警告:
sourceSets {
main {
java {
srcDir "${projectDir}/build/generated/source/proto/main/java"
}
}
}
警告:
Execution optimizations have been disabled for task ':generateProto' to ensure correctness due to the following reasons:
- Gradle detected a problem with the following location: '/build/generated/source/proto/main'. Reason: Task ':generateEffectiveLombokConfig' uses this output of task ':generateProto' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.4.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.
如何确保在Lombok任务之前完成所有ProtoBuf任务?
I use lombok and protobuf simultaneously in gradle. This generates the tasks generateEffectiveLombokConfig
and generateProto
which are independent. Yet the lombok task should depend on the protobuf task, otherwise the code generated by lombok is referring to Java code not yet generated by protoc.
syntax = "proto3";
package my.example.v1;
message Task {
string id = 1;
repeated string names_to_print = 2;
}
package org.example;
import lombok.experimental.UtilityClass;
import my.example.v1.*;
@UtilityClass
public class Worker {
public void work(TaskOuterClass.Task task) {
// do something
}
}
plugins {
id 'java'
id 'io.freefair.lombok' version '6.4.3'
id 'com.google.protobuf' version '0.8.18'
}
group 'org.example'
repositories {
mavenCentral()
}
dependencies {
implementation "com.google.protobuf:protobuf-java:3.20.1"
implementation "com.google.protobuf:protobuf-java-util:3.20.1"
}
I tried to add the output of protobuf as sourceSet to make sure the protobuf task is performed first, yet I get a warning:
sourceSets {
main {
java {
srcDir "${projectDir}/build/generated/source/proto/main/java"
}
}
}
warning:
Execution optimizations have been disabled for task ':generateProto' to ensure correctness due to the following reasons:
- Gradle detected a problem with the following location: '/build/generated/source/proto/main'. Reason: Task ':generateEffectiveLombokConfig' uses this output of task ':generateProto' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.4.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.
How can I make sure that all protobuf tasks are done before the lombok tasks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将任务依赖性如下
you put task dependency as below