publishing {
    publications {
        maven(MavenPublication) {
            pom.withXml {
                def pomNode = asNode()
                pomNode.dependencyManagement.replaceNode {}

                // simply remove dependencies without a version
                // version-less dependencies are handled with dependencyManagement
                // see https://github.com/spring-gradle-plugins/dependency-management-plugin/issues/8 for more complete solutions
                pomNode.dependencies.dependency.findAll {
                    it.version.text().isEmpty()
                }.each {
                    it.replaceNode {}
                }
            }
            artifactId project.name
            from components.java
            artifact sourcesJar
            artifact javadocJar
            artifact source:"${sourceSets.main.output.classesDir}/META-INF/grails-plugin.xml",
                     classifier:"plugin",
                     extension:'xml'
        }
    }

    repositories {
        maven {
            credentials {
                username System.getenv('GRAILS_CENTRAL_USERNAME') ?: project.properties.get('grailsPluginsUsername')
                password System.getenv("GRAILS_CENTRAL_PASSWORD") ?: project.properties.get('grailsPluginsPassword')
            }

            if(version.endsWith('-SNAPSHOT')) {
                url "https://repo.grails.org/grails/plugins3-snapshots-local"
            }
        }
    }
}

task install(dependsOn: project.tasks.withType(PublishToMavenLocal))
