With 0.7.0, I tried using the publishing plugin li...
# gradle
i
With 0.7.0, I tried using the publishing plugin like this:
Copy code
val publishing: NamedDomainObjectContainer<Publication> by extensions
publishing {
     "Module"(MavenPublication::class) {
        // more code here
    }
}
but I get this error:
Element 'publishing' of type 'org.gradle.api.publish.internal.DefaultPublishingExtension_Decorated' from container 'org.gradle.api.internal.plugins.DefaultConvention@260e45a' cannot be cast to 'org.gradle.api.NamedDomainObjectContainer'
Am I doing something wrong, or is this not supported yet?
OK, I found out that this is the way to do it:
Copy code
val publishing : NamedDomainObjectContainer<Publication> = the<PublishingExtension>().publications
b
The extension is of type
PublishingExtension
so the following should give you access to it:
Copy code
val publishing: PublishingExtension by extensions
i
But cannot apply a closure to
publishing
so I have to write two lines
Copy code
`
val publishing: PublishingExtension by extensions
val publications: NamedDomainObjectContainer<Publication> = publishing.publications
in that case.
b
you can use Kotlin’s
apply
as in
publishing.apply { …
but there’s nothing wrong with your solution
I would omit the type of the
publications
val though
it’s unnecessary
i
Thanks for the tips