Can I create a Maven POM-only (BOM) build using the Gradle maven plugin to be deployed to Nexus?

后端 未结 4 394

I have a Gradle project which uses Spring\'s dependency management plugin to define a list of dependency versions. I am also using the Maven plugin to deploy the project to

4条回答
  •  余生分开走
    2021-01-13 03:11

    You could have a build.gradle such as:

    apply plugin: 'maven-publish'
    apply plugin: 'signing'
    
    publishing {
        repositories {
            maven {
                def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
                def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
                url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
                credentials {
                    username ossrhUsername
                    password ossrhPassword
                }
            }
        }
    
        publications {
            maven(MavenPublication) {
                groupId = 'com.example.id'
                artifactId = 'my-artifact-id'
                version = '1.0.0'
    
                pom.withXml {
                    asNode().children().last() + {
                        resolveStrategy = Closure.DELEGATE_FIRST
    
                        name 'My Lib Name'
                        description 'My Lib Description'
                        url 'https://example.com/id/lib'
    
                        licenses {
                            license {
                                name 'The Apache License, Version 2.0'
                                url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                            }
                        }
                        scm {
                            connection 'scm:git:git@example.com:acdcjunior/lib/id.git'
                            developerConnection 'scm:git:git@example.com:acdcjunior/lib/id.git'
                            url 'git@example.lib/id.git'
                        }
                        developers {
                            developer {
                                id 'someone'
                                name 'Someone Name'
                                email 'someone@example.com'
                            }
                        }
                        dependencies {
                            dependency {
                                groupId 'com.example.other'
                                artifactId 'some-dependency'
                                version '1.0.0'
                            }
                            dependency {
                                groupId 'org.apache.commons'
                                artifactId 'commons-lang3'
                                version '3.9'
                            }
                        }
                    }
                }
            }
        }
    }
    
    signing {
        sign publishing.publications.maven
    }
    

    Example of a project using this: https://github.com/acdcjunior/domain-id/blob/master/domain-id-all/build.gradle

提交回复
热议问题