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

Decide what to do for plugins modifying upgraded properties at execution time #25836

Closed
asodja opened this issue Jul 20, 2023 · 8 comments
Closed
Labels
a:investigation Issues requiring decision or investigation in:provider-api property lazy provider MapProperty ListProperty DirectoryProperty is:blocker Needs to be resolved to unblock another issue p:lazy-migration Issues covered by migration to an all-lazy API
Milestone

Comments

@asodja
Copy link
Member

asodja commented Jul 20, 2023

It seems some plugins modify property value in doFirst, e.g. ErrorPronePlugin does:

tasks.withType<JavaCompile>().configureEach {
  doFirst("Configure forking for errorprone") {
     options.isFork = true
  }
}

see source.

And after property upgrade we get:

* What went wrong:
Execution failed for task ':compileJava'.
> The value for task ':compileJava' property 'options' property 'fork' is final and cannot be changed any further.

Should we/can we handle that somehow? I guess in the end such plugins will need an update to be compatible

Let's decide what to do here for old plugins. Right now it seems difficult to make such plugins work with property upgrades.

Should we already display some warning at execution time even for "raw" type properties?

@asodja asodja added the p:lazy-migration Issues covered by migration to an all-lazy API label Jul 20, 2023
@asodja
Copy link
Member Author

asodja commented Jul 20, 2023

We actually do the same in our code:

if (isModule && !isSourcepathUserDefined) {
compileOptions.setSourcepath(getProjectLayout().files(sourcesRoots));
}

This is related to finalization of properties.

@lptr
Copy link
Member

lptr commented Jul 24, 2023

I think this is a good thing. We introduced property finalization partially because we wanted to prevent this very use case. We couldn't do it for JavaBean properties, but by converting them to lazy props we get this validation.

If you look at it like that (i.e. a new kind of validation), it is clear what we should do: introduce it as a deprecation warning, and break in the next major.

We can implement this by treating @UpgradedPropertys specially, so if someone tries to modify their value we can emit a deprecation warning. We might already have some functionality implemented to do this... 🤔

@asodja
Copy link
Member Author

asodja commented Jul 24, 2023

So ErrorProne basically wants to make sure fork = true is really used. So it try to configure the task last with doFirst:

tasks.withType<JavaCompile>().configureEach {
  doFirst("Configure forking for errorprone") {
     options.isFork = true
  }
}

I guess with Property solution would be:

tasks.withType<JavaCompile>().configureEach {
     options.isFork = true
     options.isFork.finalizeValue()
}

I wonder if we should have Property.finalizeValue that fails on change and Property.finalizeValueNoException that would just warn if value tries to be changed.

@lptr
Copy link
Member

lptr commented Aug 10, 2023

Discussed this with @adammurdoch today. Tasks not modifying their inputs is definitely our goal in the foreseeable future. We should not break tasks that do this without warning, though. There seems to be two approaches available to us:

  1. For @UpgradedPropertys we initially only "soft-finalize", i.e. we show deprecation when property is modified after finalization. In the next major we change the deprecation to an exception (=hard finalization) as usual. Note that we already had this kind of soft-finalization in place when we originally started finalizing Property inputs, so it is probably quite easy to reinstate this for @UpgradedPropertys.

  2. We instrument setters and start soft-finalizing them very soon. Doing means we can already do hard finalization when upgrading properties in the next major.

An additional benefit of 2) is that it applies to every JavaBean property, e.g. to properties of custom tasks introduced in builds etc. so we can phase out all the bad usage patterns out there. Meanwhile 1) only addresses bad usage patterns for @UpgradedPropertys.

OTOH, with 2) we would only address modifications via setters. For example, it wouldn't cover mutating multi-valued properties like lists wrt adding/removing items. Deprecating these mutations too could be possible, but would mean more work.

@ov7a ov7a added the a:investigation Issues requiring decision or investigation label Sep 1, 2023
@asodja asodja added the is:blocker Needs to be resolved to unblock another issue label Sep 6, 2023
@ov7a ov7a added the in:provider-api property lazy provider MapProperty ListProperty DirectoryProperty label Sep 12, 2023
@lptr
Copy link
Member

lptr commented Feb 27, 2024

ErrorProne should probably configure fork = true via normal configuration, and then add a check during runtime, and fail if the user somehow forced it back to false.

@asodja
Copy link
Member Author

asodja commented Jun 19, 2024

I've opened tbroyer/gradle-errorprone-plugin#97 for ErrorProne.

@lptr
Copy link
Member

lptr commented Oct 18, 2024

Can we close this now since we introduced lenient finalization for upgraded properties?

@asodja
Copy link
Member Author

asodja commented Oct 19, 2024

Yes we can, thanks!

We implemented lenient finalization for migrated properties in #30715, that fixes also this issue.

@asodja asodja closed this as completed Oct 19, 2024
@github-actions github-actions bot added pending:milestone Indicates that the completed issue requires a milestone to-triage labels Oct 19, 2024
@ov7a ov7a added this to the 8.12 RC1 milestone Oct 21, 2024
@ov7a ov7a removed to-triage pending:milestone Indicates that the completed issue requires a milestone labels Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:investigation Issues requiring decision or investigation in:provider-api property lazy provider MapProperty ListProperty DirectoryProperty is:blocker Needs to be resolved to unblock another issue p:lazy-migration Issues covered by migration to an all-lazy API
Projects
None yet
Development

No branches or pull requests

3 participants