gradle项目转maven

发布于 / 随记 / 0条评论 / Tags: maven,gradle / 2 次浏览

gradle项目越来越多,但是公司项目只能用maven,转换方法如下

1.每个项目的build.gradle(或者gradle.kts)加入插件

groovy:

plugins {
    id 'maven'
}

kotlin

plugins {
    maven
}

2.加入task

groovy


task writeNewPom {
    doLast {
        pom {
            project {
                inceptionYear '2008'
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        distribution 'repo'
                    }
                }
            }
        }.writeTo("$buildDir/newpom.xml")
    }
}

kotlin

task("writeNewPom") {
    doLast {
        maven.pom {
            withGroovyBuilder {
                "project" {
                    setProperty("inceptionYear", "2008")
                    "licenses" {
                        "license" {
                            setProperty("name", "The Apache Software License, Version 2.0")
                            setProperty("url", "http://www.apache.org/licenses/LICENSE-2.0.txt")
                            setProperty("distribution", "repo")
                        }
                    }
                }
            }
        }.writeTo("$buildDir/newpom.xml")
    }
}

3.gradle writeNewPom 运行即可

    评论区(暂无评论)