Failed to apply plugin class 'org.gradle.api.publish.plugins.PublishingPluginRules'

Working on gradle upgrade from gradle 6.5.1 to gradle 7.4.2
Lets say mono-repo folder has
Project-Folder/build.gradle
buildscript {
dependencies {
classpath files(“/opt/custom-gradle-plugins.jar”)
}
}
apply plugin: ‘com.myOwnProj.build.Publish’
version = ‘1.0’

In custom plugin, I have applied maven-publish plugin and looks like it was not applying successfully

But throwing error for gradle 7.4.2
as below
Cannot add rule PublishingPluginRules#tasksDependOnProjectPublicationRegistry(ModelMap, PublishingExtension) for model element ‘tasks’ at state Initialized as this element is already at state SelfClosed.

I think you should add like this

abstract class MavenRepositoryPlugin implements Plugin<Project> {

    @Override
    void apply(Project project) {
        project.pluginManager.apply(MavenPublishPlugin.class)
        //do something
        }
}