Can a custom plugin print its version?

I have a custom plugin and I’d like to to print out its version and some other information during apply. I know I can log during apply but i’m not sure how to add content to my plugin’s manifest so it can be used during this phase.

How do you add manifest element to a custom plugin during its build/product?

You can use the ‘manifest’ method on the ‘Jar’ class/task.

http://www.gradle.org/docs/current/groovydoc/org/gradle/api/tasks/bundling/Jar.html

http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.bundling.Jar.html

That’s what I did. Thanks.

I added a manifest by modifying build.gradle

jar {
    manifest {
        attributes("Implementation-Version": version)
    }
}

Then I modified my apply code adding this:

try {
            URLClassLoader cl = (URLClassLoader) getClass().getClassLoader()
            URL url = cl.findResource("META-INF/MANIFEST.MF")
            Manifest manifest = new Manifest((url.openStream()))
            manifest.mainAttributes.each {project.logger.lifecycle("MyPlugin: ${it}") }
        } catch (IOException e) {
            project.logger.warn("Cannot ready plugin's manifest. Cosmetic issue.")
        }