This message was deleted.
# plugin-development
s
This message was deleted.
v
afterEvaluate
is practically never acceptable except for very rare cases 😄
t
It'd probably be better if your extension exposed an imperative rather than declarative API, and directly register the repository when called.
extension.doThis()
rather than
extension.configured = "this"
. (you could see this similarly to
useXxx()
methods on a
Test
task: configurable once, not reconfigurable; thus imperative rather than declarative)
☝️ 1
k
How would I get access to the
RepositoryHandler
from the extension, then?
v
One alternative way if acceptable would be to create an extension on
project.repositories
instead.
Then the user can use that method like
Copy code
repositories {
    myExtension {
        myRepository()
    }
}
from both, Groovy DSL and Kotlin DSL.
But either way, just give the repository container to the extension when you create it. It might work automatically if you register the extension on the repository handler like it does for
Project
, if not you just supply it explicitly as constructor arg to the
create
call.
k
According to the API docs,
RepositoryHandler
is not `ExtensionAware`; would that present a problem?
v
No, just close your eyes, ignore common sense, and cast it 🙂
Everything Gradle creates is
ExtensionAware
but only the least declare it explicitly. Even your instances, like your
MyExtension
instance is
ExtensionAware
. I usually tend to also always declare it explicitly for my types that do not inherit it already anyway.