Custom plugin: Maven-Publish plugin - add default publication if there is no defined in build.gradle

Viewed 82

I am building a custom plugin. I would like to add a Java publication if there is no defined in build.gradle file. This is my current code:

  project.afterEvaluate {
       project.plugins.withType<MavenPublishPlugin> {
            configure<PublishingExtension> {                
                     if (publications.isEmpty()) {
                          project.logger.info("Publish is empty, creating MavenPublish - java publication")
                          defineJavaPublication(this)
                     }
                }            
       }
}

I had to use project.afterEvalute to get it working. Is there some better way to do this? Project.afterEvaluate is marked as deprecated - what should I use instead?

0 Answers
Related