Skip to content

Replace use of convention mappings with PropertyState and Provider #9891

New issue

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

By clicking “No 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? No Sign in to your account

Closed
wilkinsona opened this issue Jul 28, 2017 · 1 comment
Closed
Labels
type: enhancement A general enhancement
Milestone

Comments

@wilkinsona
Copy link
Member

We current use Gradle's support for convention mappings in a few places in the Gradle plugin. This is an internal API so it'd be nice to move off it. Gradle 4.0 introduced PropertyState and Provider that can be used to achieve the same end result.

I have some reservations about the PropertyState and Provider APIs in their current form. As far as I can tell you have to be comfortable with losing some type safety. For example, if you want to have a List<String> property, you cannot have a PropertyState<List<String>> and Provider<List<String>> for it. Instead, have to make do with PropertyState<List> and Provider<List> and hope for the best.

Convention mappings have a similar lack of type safety but it doesn't leak into a task's own API (unlike setThings(Provider<List> thingsProvider) would for example). I also believe that convention mappings benefit from some of Groovy's type coercion and property states do not.

We may well decide that continuing to use convention mappings is the least bad option here.

@wilkinsona
Copy link
Member Author

wilkinsona commented Jul 28, 2017

There's a Gradle issue that relates to this. Thanks to some pointers from @eskatos, I now realise that things aren't as bad as I had feared.

The API for the Provider side of things is fine. You can do this:

Provider<List<String>> provider = project.provider(() -> Arrays.asList("a", "b", "c"));

This is important as user code may want to create such a Provider and we want to be able to offer setters that take Provider<List<String>> and the like.

The PropertyState side of things is a bit more awkward, but the problem can be worked around by casting:

PropertyState<List<String>> listState = (PropertyState<List<String>>) (Object) project
        .property(List.class);

This isn't great, but it'll be hidden in the plugin's internals and allow the API to use Provider<List<String>> which is what really matters.

@wilkinsona wilkinsona added this to the 2.0.0.M5 milestone Jul 28, 2017
wilkinsona added a commit that referenced this issue Sep 26, 2017
This commit reworks BootRun so that it no longer subclasses JavaExec.
This provides Boot with greater control of how the executed JVM is
configured, including the possibility of using @option to provide args
and JVM args via the command line (gh-1176). It also allows some usage
of convention mappings to be removed in favour of PropertyState and
Provider (gh-9891). For users who relied up the advanced (and rather
complex) configuration options provided by JavaExec, an escape hatch
is provided by allowing the JavaExecSpec that's used to execute the
JVM to be customized.

Closes gh-9884
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant