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

buildDir is not lazily evaluated for determining the generated files base directory #674

Open
simon-spinner opened this issue Feb 3, 2023 · 6 comments · Fixed by #676
Open
Assignees

Comments

@simon-spinner
Copy link

If I change the buildDir in a gradle project to a non-default location, the plugin (in version 0.9.2) does not consider the changed buildDir for the output directory of the generated source code if it has already been initialized. Workaround is to initialize the plugin after changing the buildDir using apply:

buildDir = ....
apply(plugin = "com.google.protobuf")

The plugin should be able to lazily detect changes to the buildDir so that I can declare it in the plugins block the usual way.

@rougsig
Copy link
Collaborator

rougsig commented Feb 3, 2023

Hello, could you please provide an example project? Or full reproducible gradle configuration file?

@ejona86
Copy link
Collaborator

ejona86 commented Feb 3, 2023

Unfortunately, for IDE support, I don't think we can delay initialization of the build directory. There's some ways to fix it today, but they'd go away shortly as we rework the IDE support to not require adding old plugins like idea.

I don't think this was regressed when I emulated generatedFilesBaseDir. The extension has been eagerly grabbing the buildDir for a while now, I think.

@simon-spinner
Copy link
Author

In our setup the build output directories are outside of the source tree. That's why we change the buildDir property in the gradle project. However, we have some eclipse users and we had to manually configure the eclipse plugin to pick up the generated sources as source folders. As it was hard to get Eclipse to work with source folders outside of the workspace, we set the generatedFilesBaseDir property to a location inside the source tree.

When switching to version 0.9.2, the build output directories inside the source tree would suddenly show up containing the protobuf generated sources (conflicting with another build system we use). The emulated generatedFilesBaseDir thus doesn't have the effect anymore we relied on so far. This is not a show-stopper, as in the meantime you included eclipse support allowing us to remove the generatedFilesBaseDir setting and our customized eclipse plugin setttings. So far that seems to work good. It just took quite some time to figure out how to get the rid of the build directories in the source tree.

@ejona86
Copy link
Collaborator

ejona86 commented Feb 3, 2023

Ah, yeah, that sounds "fun."

We are creating the directories for IDEs today in afterEvaluate{}, and it seems we are going to be forced to do that long-term. So we can tweak some things to be able to see changes to buildDir. It think the idea would be to change defaultGeneratedFilesBaseDir to be a GString or provider.

But that would retain a reference to project, so we'll need to swap to layout.getBuildDirectory()... which looks okay. I thought there was a missing API relating to DirectoryProperty in an older version of Gradle we support, but it doesn't appear to be the ones needed here.

ejona86 added a commit to ejona86/protobuf-gradle-plugin that referenced this issue Feb 9, 2023
This causes the plugin to use the correct configuration when users
use a non-default buildDir.

Fixes google#674
@ejona86 ejona86 self-assigned this Feb 9, 2023
@ejona86 ejona86 modified the milestones: 0.10.0, 0.9.2 Feb 9, 2023
@ejona86 ejona86 closed this as completed in 7deeb2a Feb 9, 2023
ejona86 added a commit to ejona86/protobuf-gradle-plugin that referenced this issue Feb 10, 2023
This causes the plugin to use the correct configuration when users
use a non-default buildDir.

Note that for IDEs we create directories in afterEvaluate{}. It is
possible for the user's own afterEvaluate{} to change buildDir. In that
case, the task will output to the 'correct' directory but the mkdirs for
IDEs can be the 'old' buildDir. But users shouldn't be using
afterEvaluate{}, so we don't care and there's no real fix anyway.

Fixes google#674
@ejona86 ejona86 reopened this Feb 13, 2023
@ejona86
Copy link
Collaborator

ejona86 commented Feb 13, 2023

With my other fix, things are probably working if you are careful. But I think it depends on when tasks are configured. We should swap some other buildDir usages over to using the provider as well.

@ejona86 ejona86 removed this from the 0.9.2 milestone May 4, 2023
@Deepanshu9376
Copy link

Deepanshu9376 commented Aug 12, 2023

Is this issue still open, if yes i would like to contribute, please assign this to me.

@ejona86 ejona86 assigned Deepanshu9376 and unassigned ejona86 Aug 14, 2023
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

Successfully merging a pull request may close this issue.

4 participants