Reference function on Gradle extension plugin configuration

59 views Asked by At

I am currently writing a Gradle plugin on Java.

I've successfully written a plugin able to receive String parameters con its configuration. However, I would like to pass instead of the value of the arguments a reference to a function on a gradle file so to execute it for getting the String argument. Is it possible? How should I performe it?

My current code is the following:

 public class DemoPluginExtension {

    private String commitId = "";

    public String getCommitId() {
       return commitId;
    }

    public void setCommitId(String commitId) {
        this.commitId = commitId;
    }
}

I have a gradle.build file with a code able to extract the commitId, lets call it getGitCommitIdInfo. So, I am able to use the plugin as follows:

demoSetting {

    def commitIdfInfo = getGitCommitIdInfo()
    commitId = commitIdfInfo

}

What I would like to perform is to use the plugin like follows:

demoSetting {

    commitIdfunc = this.&getGitCommitIdInfo

}

But I do not know how to write the DemoPluginExtension code.

Any suggestion is going to be welcomed.

Thanks a lot!

0

There are 0 answers