Setting up a Default Publish Jar in a Custom Plugin


I have a project which uses a custom plugin written a few years back.

This hangs a couple of extra copy tasks onto the standard java tasks. It looks a bit like this:

class MyPlugIn implements Plugin {

void apply(Project project) {



However, if I want to do a default maven style publish for most projects that use the plugin (will be disabled for one or two projects) - is there a way I can set up a default publish from inside the plugin? In the past, I’ve done stuff like this directly in the gradle file e.g.:

publishing {
publications {
defaultJar(MavenPublication) {
artifact tasks.getByName(‘create-jar’)
groupId ‘XXX’
artifactId “???”
version “1.0-SNAPSHOT”

repositories {
maven {
name ‘XXX’
url ‘URL’
credentials {
username = ???
password = ???