新发布1.0版本,会提示报错
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project mydemo: Failed to deploy artifacts: Could not transfer artifact site.starsone:mydemo:jar:1.0 from/to myLocalRepo (http://localhost:9888/repository/maven-releases/): Transfer failed for http://localhost:9888/repository/maven-releases/site/starsone/mydemo/1.0/mydemo-1.0.jar 400 Repository does not allow updating assets: maven-releases
需要去该仓库里的设置进行以下配置:
4.打包后出现boot-inf文件夹
如果项目中有maven-plugin插件的话,需要配置skip属性为true,否则会出现打包之后出现BOOT-INF,导致引入依赖时没法使用
Gradle中使用
Gradle主要是以上传Android的aar包为例,如果是普通jar包,可以参考官方文档
使用maven-publish'插件:
Gradle7.0版本之后都必须使用这个了,但此插件也支持旧版本的Gradle来使用
单Module发布
这里,假设我们只有一个module,如下图目录所示:
有一个auth的库需要进行发布,我们想要将此库发布在本地私有库中,则需要对其的build.gradle
进行更改,如下面代码(省略了android闭包等部分:
plugins {
id 'com.android.library'
id 'maven-publish'
}
//定义你的私有库地址和密码
def NEXUS_MAVEN_URL = "http://localhost:9888/repository/maven-releases/"
def NEXUS_USERNAME = "admin"
def NEXUS_PASSWORD = "admin"
//对饮的依赖坐标和描述
def POM_NAME = "webviewbase"
def POM_GROUP_ID = "site.starsone"
def POM_ARTIFACT_ID = "webviewbase"
def POM_VERSION = "1.5"
def POM_PACKAGING = "aar"
def POM_DESCRIPTION = "webviewbase基础库"
aftereva luate {
publishing {
publications {
aar_pub(MavenPublication) {
//定义group和版本
group = POM_GROUP_ID
//定义构造物id
artifactId = POM_ARTIFACT_ID
version = POM_VERSION
pom {
name = POM_NAME
description = POM_DESCRIPTION
url = 'http://www.example.com/library'
//类型设置为aar
packaging = POM_PACKAGING
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'starsone'
name = 'stars-one'
email = 'stars-one@example.com'
}
}
}
//带上依赖 ,否则会报错
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
def scopes = [configurations.compile]
if (configurations.hasProperty("api")) {
scopes.add(configurations.api)
}
if (configurations.hasProperty("implementation")) {
scopes.add(configurations.implementation)
}
if (configurations.hasProperty("debugImplementation")) {
scopes.add(configurations.debugImplementation)
}
if (configurations.hasProperty("releaseImplementation")) {
scopes.add(configurations.releaseImplementation)
}
scopes.each { scope ->
scope.allDependencies.each {
if (it instanceof ModuleDependency) {
boolean isTransitive = ((ModuleDependency) it).transitive
if (!isTransitive) {
println "<<<< not transitive dependency: [${it.group}, ${it.name}, ${it.version}]"
return
}
}
if (it.group == "${project.rootProject.name}.libs" || it.version == 'unspecified') {
return
}
if (it.group && it.name && it.version) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
dependencyNode.appendNode('scope', scope.name)
}
}
}
}
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar&q