Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to compile .proto files to project folder? #11711

Closed
AlexInCube opened this issue Nov 27, 2024 · 6 comments
Closed

How to compile .proto files to project folder? #11711

AlexInCube opened this issue Nov 27, 2024 · 6 comments
Labels

Comments

@AlexInCube
Copy link

I want to compile just the files into the root of the project, but I'm having trouble. I tried to make this code, but it gives an error.
My proto files are above the Java project in the hierarchy, because the Java project is one of the projects in the monorepository.

Illegal char <:> at index 81: C:\webprojects\micro-keynadi\apps\eximia-auth\build\generated\source\proto\main\C:\webprojects\micro-keynadi\apps\eximia-auth\src\main\generatedProto
plugins {
    id 'java'
    id 'eclipse'
    id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.8'
    id 'com.google.protobuf' version '0.9.4'
}

sourceSets {
    main {
        proto {
            srcDir '../../proto'
        }
        java {
            srcDir "${projectDir}/src/main/generatedProto"
        }
    }
}


protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.25.5"
    }
    plugins {
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java:1.68.1'
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                java {
                    outputSubDir = "${projectDir}/src/main/generatedProto"
                }
            }
            task.plugins {
                grpc {
                    outputSubDir = "${projectDir}/src/main/generatedProto"
                }
            }
        }
    }
}
@ejona86
Copy link
Member

ejona86 commented Nov 27, 2024

outputSubDir can't move it to another part of the tree. It is a subdirectory. That's why there's the random broken C: in the middle of the string "...proto\main\C:\webprojects...". I suggest deleting the outputSubDir lines

@AlexInCube
Copy link
Author

then how do i do the compilation to the folder i want? i have spent hours trying to figure it out but nothing works.

@ejona86
Copy link
Member

ejona86 commented Nov 27, 2024

You can use a separate Sync or Copy task into the folder of your choosing. google/protobuf-gradle-plugin#722 tracks letting it be configured.

@kannanjgithub
Copy link
Contributor

kannanjgithub commented Nov 28, 2024

The generateProtoTasks plugin uses the default outputSubDir of build/generated/source/proto/main under which it will create a "java" and "grpc" subdirs for the generated sources for the protos and the service respectively. So in your source sets you need to also change the paths for Java (for IDEs to pick up) from

    java {
        srcDir "${projectDir}/src/main/generatedProto"
    }

to

    java {
        srcDirs 'build/generated/source/proto/main/grpc'
        srcDirs 'build/generated/source/proto/main/java'
    }

Refer (example).

@ejona86
Copy link
Member

ejona86 commented Dec 3, 2024

srcDirs 'build/generated/source/proto/main/grpc' will actually only break things. The protobuf plugin adds those source dirs, with proper dependency information so Gradle knows when they need to be rebuilt. The problem with IDEs is they require the directories to exist when it loads the project. I think that's a different problem than what was being seen in this issue.

@ejona86
Copy link
Member

ejona86 commented Dec 20, 2024

Seems like this is resolved. If not, comment, and it can be reopened.

@ejona86 ejona86 closed this as completed Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants