How to avoid specifying `publishing.repositories` for every new project?

Hi,

Every new project that we create in our company, has the following publishing.repositories setting:

publishing {
    repositories {
        maven {
            credentials {
                username project.findProperty('nexusUsername')
                password project.findProperty('nexusPassword')
            }

            if (project.version.endsWith('-SNAPSHOT')) {
                url 'https://nexus.example.com/content/repositories/snapshots'
            } else {
                url 'https://nexus.example.com/content/repositories/releases'
            }
        }
    }
}

What is a good way to avoid repeating this over and over again? Using a plugin (e.g. apply plugin: 'exampleNexus')?

Thanks in advance.

Yes, this belongs in a convention plugin that projects in your company use.

1 Like