[英]Gradle compile dependency outside of project
I have a frontend and a backend repository for my app. 我的应用程序有一个前端和一个后端存储库。 The backend is written in Go and serves the API over gRPC.
后端使用Go编写,并通过gRPC提供API。 The generated gRPC Java files end up in
backend-repo/proto-gen/java/
(so backend-repo/proto-gen/java/com/myApp/Users.java
). 生成的gRPC Java文件最终位于
backend-repo/proto-gen/java/
(因此backend-repo/proto-gen/java/com/myApp/Users.java
)中。
In my frontend android repo I have submoduled the backend repo to a folder called server
. 在我的前端android repo中,我已将后端repo调制为一个名为
server
的文件夹。 I want to modify my build.gradle
to compile the .java
files from the backend. 我想修改我的
build.gradle
以从后端编译.java
文件。
android-repo/
app/
build.gradle
server/proto-gen/java/com/myApp/
Users.java
AnotherService.java
I'm very new to Android development and am struggling to figure out the right approach. 我对Android开发非常陌生,正在努力寻找正确的方法。
This is a snippet from my app/build.gradle
but it fails because it can't find the package com.google.protobuf
. 这是我的
app/build.gradle
的代码段,但由于找不到包com.google.protobuf
而失败。
task compileGrpc (type: JavaCompile) {
source = fileTree(dir: '../server/proto-gen/java/', include: '**/*.java')
destinationDir = file('build/classes')
classpath = files('../server/proto-gen/java/')
options.compilerArgs = ["-sourcepath", "$projectDir/../server/proto-gen/java/"]
}
dependencies {
compile 'com.google.protobuf:protobuf-java:3.0.0-alpha-2'
compileGrpc.execute()
}
You can add your dependencies like 您可以像添加您的依赖项
dependencies {
classpath files('server/proto-gen/java/com/myApp/')
}
This will accept relative path. 这将接受相对路径。
Simply including the path to the src
sourceset for the project would include them within the compilation: 只需将项目的
src
的路径包括在内,即可在编译中包括它们:
android {
...
sourceSets {
main {
java.srcDirs = [java.srcDirs, 'server/proto-gen/java']
}
}
}
You'll be able to see the src files/directories included within the Android View/Project Explorer on the right side and edit the files directly. 您将能够在右侧看到Android View / Project Explorer中包含的src文件/目录,并直接编辑文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.