概述
由于maven插件已经废弃,被maven-publish插件替代了,有些老项目还在使用maven插件,所以需要知道如何升级,这里做一个对比。
maven插件
以下是总体配置,具体还会涉及:是否上传源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| apply plugin: 'maven'
uploadArchives { repositories { mavenDeployer { def isRelease = project.AAR_BUILD_TYPE == "release" if (isRelease) { repository(url: project.RELEASE_URL) { authentication(userName: project.MAVEN_USERNAME, password: project.MAVEN_PASSWORD) } pom.version = project.AAR_VERSION } else { repository(url: project.SNAPSHOT_URL) { authentication(userName: project.MAVEN_USERNAME, password: project.MAVEN_PASSWORD) } pom.version = project.AAR_SNAPSHOT_VERSION } pom.groupId = project.POM_GROUPID pom.artifactId = project.POM_ARTIFACTID pom.name = project.POM_NAME pom.packaging = project.POM_PACKAGING } } }
|
maven-publish插件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| apply plugin: 'maven-publish'
publishing { repositories { maven { url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" credentials { username = "sonatypeUsername" password = "sonatypePassword" } } } publications { maven(MavenPublication) { afterEvaluate{ artifact(tasks.getByName("bundleReleaseAar")) } artifact "$buildDir/outputs/aar/${project.name}-release.aar" groupId = 'com.example' artifactId = 'my-library' version = '1.0.0'
pom { name = 'My Library' description = 'A description of my library' url = 'https://github.com/example/my-library' } } }
}
|
结合agp插件,指定产物:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| afterEvaluate { publishing { repositories { } }
publications { maven(MavenPublication) { from components.release artifact sourcejar } } }
|
参考资料
maven插件 和 maven-publish 插件的区别
Maven 插件与 Maven-Publish 插件的差异