"Could not find any public constructor for class" in plugin


(Steve Cohen) #1

I’m developing a plugin that will package a JDK tarball into an rpm. I try to follow this model from the user’s guide:

apply plugin: GreetingPlugin

greeting.message = 'Hi from Gradle'

class GreetingPlugin implements Plugin<Project> {
    void apply(Project project) {
        // Add the 'greeting' extension object
        project.extensions.create("greeting", GreetingPluginExtension)
        // Add a task that uses the configuration
        project.task('hello') << {
            println project.greeting.message
        }
    }
}

class GreetingPluginExtension {
    def String message = 'Hello from GreetingPlugin'
}

Now here’s mine:

class JdkRpmPlugin implements Plugin<Project>{

    @Override
    public void apply(Project project) {
        project.extensions.create("versioner", JdkVersionerExtension)
         }
        ...
    }
    
    class JdkVersionerExtension {
        def String majorVersion
        def String minorVersion
        def String architecture
        def String getVersion() {
            "1.${majorVersion}.0_${minorVersion}"
        }
    }

}

(Stefan Oehme) #2

You created an inner class, which needs a reference to its outer class to be instantiated. What you probably wanted is a static nested class.


(Steve Cohen) #3

Thanks. I was about to post more explanation, and I “solved” it by moving my extension class to its own groovy file. But your solution is simpler.