Android Other

Plugin with id 'maven' not found

2022-07-21  本文已影响0人  WilsonMing

如果你项目的gradle版本>7.0,在项目中引用maven插件

apply plugin: 'maven'

会报错
Plugin with id 'maven' not found.

因为在In Gradle 7.x官网已经废弃了,
The maven plugin has been removed. You should use the maven-publish plugin instead.

image.png
apply plugin: 'groovy'
apply plugin: 'maven'

repositories {
    mavenCentral()
}

dependencies {
    //xxx
}
uploadArchives{
//    打包成一个jar    引用jar  生成这个三个信息
    repositories.mavenDeployer {
//项目名
        pom.groupId = 'com.x'
        pom.artifactId = 'modify'
        pom.version = '1.0.0'
        repository(url: uri('../repo'))
    }
}
sourceCompatibility = "8"
targetCompatibility = "8"

需要改成

//maven插件在gradel7.0 已删除
apply plugin: 'groovy'
apply plugin: 'maven-publish'
// 或者以下写法
//plugins {
//  id 'groovy'
//  id 'maven-publish'
//}


dependencies {
//......略写
}

afterEvaluate {
    publishing {
//    配置maven-publishing插件的输出物
        publications {
            maven(MavenPublication) {
                groupId = 'com.x'
                artifactId = 'modify'
                version = '1.0.0'
            }
        }
        repositories {
            maven {
                url = uri('../repo')
            }
        }
    }
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

为什么maven-publish插件替换maven?

具体Gradle maven-publish plugin使用可参考官网文章(需翻墙)

扩展阅读

上一篇下一篇

猜你喜欢

热点阅读