-
Notifications
You must be signed in to change notification settings - Fork 274
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 set output directory for generated Java files. #682
Comments
I have the same question. Seems like none of the options work at the moment. I tried below but still the code was generated in the default directory.
and this as well generatedFilesBaseDir = "${rootDir}/buildpo" |
@manish7-thakur I wrote a dirty workaround. I did not have the time to dig into the problem myself and using protoc directly was faster. I used an exec task to run a bash script that uses the protoc command. Here is the script (generate_java.sh):
Here is the gradle exec task:
It is not flexible at all, but works for now. I hope someone looks into the problem soon. Would be great |
@manish7-thakur, see https://github.com/google/protobuf-gradle-plugin/releases/tag/v0.9.2 . generatedFilesBaseDir is fundamentally broken because it mixes the generated code output with whatever source files you have laying around. Using it can produce incorrect builds, because old generated code is not deleted. You need to use |
@ejona86 Thanks for the clarification. In my opinion is does not make sense to copy the files into the build folder in the first place. Java files are not needed there and the developer is responsible to keep his source folder clean. |
The plugin will use its own directory in the build/ directory. It deletes the existing files and dumps the new files. The The plugin now interacts properly with the sourceSets, so other plugins looking for source code should find the generated code. IDEs are a bit of a problem, but for the inane reason that they ignore the directory if it does not already exist (although we have some workarounds for that). The I do actually want to allow changing the destination directory, but so that you can create your own |
I would love to have that possibility. Looking forward to that. I still do not get why copying the .java files into the build directory. No IDE will look there for Java files. I would have to make a really dirty configuration to also use the generated java files in the build directory in my code. |
Eclipse, IntelliJ, and VSCode all will, if you are using their Gradle integration. Again, there's a problem with them ignoring the directory if the directory doesn't already exist, so right now you also need to apply the |
This does not help the build/IDE problem, because you can't use directories like src/main/java because those contain your hand-written source code and so you can't delete the files within them. You need to use a different directory which means you still have the build/IDE problem. |
In my opinion that is not true what you are saying. Gradle is definitely not looking for java source files in the build folder. That would also make no sense, because this build folder is created from gradle doing the build and is used for compiled classes. Why should a build tool look for source files in a folder, that was created by that build tool before? and here: You could change that behavior with source sets, but I would not do that. Makes it difficult for others to get your project configuration. I also saw that only for really special cases. The deletion of files is pretty easy with an own task and the delete command. You can delete files all over your projects. As example:
Works perfect even if the file is not there. Read about it here: https://docs.gradle.org/current/userguide/working_with_files.html#sec:deleting_files_example I was also a curious about what you said and tried it myself. Never tested this before. The result was as I described above. |
Hello,
first thanks for your work. I'm pretty new to Gradle, coming from Maven, and find no way to set the output directory for the generated Java files. In the moment they are copied to the build folder (working with Intellij by the way), but that does not make any sense to me. I need the compiled .class files in the build directory and the Java files in my src/... folder. I want to copy them to a specific location to use them in a Apache Kafka Streams app. Sorry to say, but in Maven this is a 5 minutes job. Can not be that difficult to configure the generation path or do I miss something here?
Any help is welcome. Thanks in advance.
Best Martin
The text was updated successfully, but these errors were encountered: