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 can I disable registering the generated Java code as sources? #739

Closed
Lifeclue opened this issue Nov 9, 2023 · 7 comments
Closed

How can I disable registering the generated Java code as sources? #739

Lifeclue opened this issue Nov 9, 2023 · 7 comments

Comments

@Lifeclue
Copy link

Lifeclue commented Nov 9, 2023

Hello.

I want to don't care how servers and clients obtain the IDL. It doesn't matter whether the way is submodule of Git or the other ways.
So I think it is better to involve the generated Java code to my source sets.
As far as I look for, You recommended it to people that using a Sync task of Gradle rather than changing generatedFilesBaseDir.
However, I met redeclaration error when I sync the generated files because the plugin registered the files as sources.
I want to do not register the generated files as sources. How can I disable the function?

Thanks.

@ejona86
Copy link
Collaborator

ejona86 commented Nov 16, 2023

I don't understand how "git submodule" is related to "manually include generated code in source set." Could you explain more of what you are trying to do? What would go wrong if you simply didn't add the sync task output to your source set?

@Lifeclue
Copy link
Author

Lifeclue commented Nov 17, 2023

Git submodule is just an example. Suppose I build my application source on a CI tool.
I should place the IDL files or compiled files to my codebase in order to use a build tool. (because this is an easy way)
The CI tool should pull both my source code and IDLs. At that time, I may use the Git submodule for example.

In the other way, I can place compiled file. This way doesn't require IDLs. However this way needs the IDL compile automation.
The Protobuf Gradle plugin can help me. The plugin builds it automatically when I build my application. I like it.
However the plugin register the compiled files as sources of IDE such as IntelliJ.
So IntelliJ shows me a redeclaration error when I move or copy the compiled files to the under src directory.
It is because the same file is both the plugin's build directory and the src directory.
The Sync task of Gradle also do like copy. So I face the same error when I use it.

Therefore, I want to do not register the compiled files as sources to the IDE.

The key point is the IDE occurs the redeclaration error when I use Sync task because same files with compiled file appear at a destination directory of the Sync task too.

@ejona86
Copy link
Collaborator

ejona86 commented Nov 17, 2023

The CI tool should pull both my source code and IDLs.

Why? It seems it should only need one or the other, but not both.

However this way needs the IDL compile automation.

Why? If you have the generated code, then you don't need the plugin. If you are putting the pre-generated code into the source set, you don't need the plugin to compile those to .class files.

@Lifeclue
Copy link
Author

The CI tool should pull both my source code and IDLs.

Why? It seems it should only need one or the other, but not both.

The CI should build the source. The source needs the generated code from IDL in order to be built. Thus, It needs IDL unless the source code contains generated code. I think the CI can obtain the IDL from Git or the other storage. It doesn't matter where it is. Anyway, the CI should obtain IDL in order to build the source code. That's why I explained 'both'.

However this way needs the IDL compile automation.

Why? If you have the generated code, then you don't need the plugin. If you are putting the pre-generated code into the source set, you don't need the plugin to compile those to .class files.

That's right but I don't have the generated code so I want to use your plugin because the plugin helps me to easy configure the compiler, to easy add plugin such as gRPC and execute at all by just one command. (Yes, the plugin is so beautiful)
I wonder why did you recommend to use the Sync task.

I also just want to change the output directory from build/generated/source/proto to src/generated. However you discouraged to change generatedFilesBaseDir and recommended to use the Sync task. So I copy the files with Gradle Sync task then IntelliJ occurred the redeclaration error because the files in build/generated/source/proto is as sources and the copied files in src/generated is also as sources.

That's why I want to disable registering the generated Java code as sources.

@ejona86
Copy link
Collaborator

ejona86 commented Nov 17, 2023

So I copy the files with Gradle Sync task then IntelliJ occurred the redeclaration error because the files in build/generated/source/proto is as sources and the copied files in src/generated is also as sources.

You don't need to add src/generated to your source sets.

The current status is you can't change the output directory. Some people wanted to check in the generated code. That allows you to not use the plugin in certain builds. The solution to that is to use Sync to copy the files out of build/. In your case, I'd suggest "do nothing" and just accept the generated code being output to build/, since it doesn't seem you need to commit the generated code.

@ejona86
Copy link
Collaborator

ejona86 commented Mar 11, 2024

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

@ejona86 ejona86 closed this as completed Mar 11, 2024
@Lifeclue
Copy link
Author

I had considered very much after I read your opinion and then I eventually decide to use protoc and shell script. The script moves the generated code to proper sourceset directory. This approach works well. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants