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

后端 未结 4 392

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 02:53

    In Gradle 6+ versions, we can use Gradle Java Platform Plugin to publish a maven-bom without many configurations and scripting.

    group 'test.platform.simple.bom'
    version '1.0.0-SNAPSHOT'
    
    repositories {
        maven {
            mavenCentral()
        }        
    }
    
    apply plugin: 'java-platform'
    apply plugin: 'maven-publish'
    
    javaPlatform {
        allowDependencies()
    }
    
    dependencies {
        constraints {
            api 'cglib:cglib-nodep:3.2.4'
            api 'junit:junit:4.12'
            // runtime 'org.postgresql:postgresql:42.2.5' <-- runtime constraint
            // api project(":core") <-- constraint from local project
            // api platform('com.fasterxml.jackson:jackson-bom:2.9.8') <-- constraint from another platform
        }
    }
    
    publishing {
      publications {
        maven(MavenPublication) {
          from components.javaPlatform
        }
      }
    }
    

    Dependencies to be managed can be defined under dependencies as api or runtime constraints. Constraints can be utilized to manage dependencies from a local project as well as from another platform/bom. Please note that we need to configure a Maven publication that uses the javaPlatform component to get it published as a maven bom artifact.

提交回复
热议问题