【发布时间】:2020-10-11 14:52:21
【问题描述】:
我有一个使用 proto 生成 DTO 的多模块 gradle 项目。根项目有两个不同的模块,inventory 和 inventory-api。 *-api 模块是具有所有.proto 定义的模块。 inventory 依赖于 inventory-api
这里是根 gradle 文件
plugins {
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
subprojects {
group = 'com.yasinbee.apifirst'
version = '0.0.1-SNAPSHOT'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java-library'
repositories {
jcenter()
}
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.1.9.RELEASE")
}
}
compileJava {
sourceCompatibility = 11
targetCompatibility = 11
}
}
这是库存 gradle 文件
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
}
dependencies {
implementation project (':inventory-api')
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-jdbc"
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.mapstruct:mapstruct:1.4.0.Final"
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.0.Final'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
还有包含所有原型的inventory-api gradle文件
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'idea'
apply plugin: 'com.google.protobuf'
dependencies {
implementation 'com.google.protobuf:protobuf-java:3.11.0'
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.13'
}
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.10.1'
}
}
我可以在 inventory-api 模块中使用生成的 proto 文件。但是,当我尝试从清单模块访问生成的文件时,出现编译错误。
生成的 proto 文件似乎没有添加到 inventory 应用程序的源集中。如何将生成的 *-api 模块的源文件添加到依赖它们的其他模块中?
【问题讨论】:
标签: java gradle protocol-buffers proto