将Gradle项目转为Maven项目(Gradle 7以上),解决 Plugin with id ‘maven‘ not found

1. 使用Maven Publishing插件来生成pom.xml

1.1 在plugins中添加 maven-publish

id 'maven-publish'

image.png

1.2 添加publishing

publishing {
    publications {
        maven(MavenPublication) {
            groupId = 'org.gradle.sample'
            artifactId = 'library'
            version = '1.1'

            from components.java
        }
    }
}

1.3 publish to Maven Local

点击IDEA右侧的gradle,然后选择'publishToMavenLocal'

就会在本地的maven仓库生成对应的jar,找到 library-1.1.pom
image.png

将该文件修改为pom.xml放入项目的根目录便完成了gradle项目转为maven项目的所有操作。

当然可能还需要一些微调。

2. 参考链接

How to convert Gradle to maven in eclipse

Maven Publish Plugin

# maven  Gradle 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×