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

Support to @Inject a SoftwareComponentFactory into a BuildService #28956

Closed
mathjeff opened this issue Apr 24, 2024 · 1 comment
Closed

Support to @Inject a SoftwareComponentFactory into a BuildService #28956

mathjeff opened this issue Apr 24, 2024 · 1 comment
Labels
a:feature A new functionality closed:not-fixed Indicates the issue was not fixed and is not planned to be

Comments

@mathjeff
Copy link
Contributor

mathjeff commented Apr 24, 2024

Expected Behavior

It would be nice if a SoftwareComponentFactory could be given to a BuildService via Injection

Current Behavior (optional)

It doesn't seem to be possible to inject a SoftwareComponentFactory directly into a BuildService via the Inject annotation.

Notice that https://docs.gradle.org/current/userguide/dependency_management.html#sec:publishing-custom-components says:

To create a custom component, you first need to create an empty adhoc component. At the moment, this is only possible via a plugin because you need to get a handle on the [SoftwareComponentFactory](https://docs.gradle.org/current/javadoc/org/gradle/api/component/SoftwareComponentFactory.html) :

I also made a repro project at https://github.com/mathjeff/gradle-samples-2/tree/main/buildservice-componentfactory where I tried to inject a SoftwareComponentFactory directly into a BuildService like this:

abstract class SampleService
@Inject
constructor(val softwareComponentFactory: SoftwareComponentFactory) : BuildService<BuildServiceParameters.None> {
  init {
    System.out.println("Created SampleService with a reference to a SoftwareComponentFactory. Nice!")
  }
}

which gives this output:

A problem occurred evaluating root project 'buildservice-componentfactory'.
> Failed to create service 'SampleService'.
   > Could not create an instance of type example.SampleService.
      > Unable to determine constructor argument #1: missing parameter of type SoftwareComponentFactory, or no service of type SoftwareComponentFactory.

Context

In AndroidX we're trying to migrate towards compatibility with project isolation which entails more artifacts to publish from some projects and consume from other projects, so we're looking into making some helper methods for making this easier.

The first thing I tried was to directly inject the SoftwareComponentFactory into the BuildService, but that didn't work.

As a workaround it seems to work to inject the SoftwareComponentFactory into a Plugin which can then pass it to the BuildService

Thanks

@mathjeff mathjeff added a:feature A new functionality to-triage labels Apr 24, 2024
@mathjeff
Copy link
Contributor Author

It looks like we probably didn't end up needing this; see https://r.android.com/3065963 .

Part of the reason that I thought we would need this was some error messages were confusing, for example this one. I shared a pull request for that issue so I think this one can probably be closed as not important

Thanks

@mathjeff mathjeff closed this as not planned Won't fix, can't repro, duplicate, stale Apr 30, 2024
@ov7a ov7a added closed:not-fixed Indicates the issue was not fixed and is not planned to be and removed to-triage labels May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:feature A new functionality closed:not-fixed Indicates the issue was not fixed and is not planned to be
Projects
None yet
Development

No branches or pull requests

2 participants