今天搭建maven私服环境,上传SNAPSHOT版本到maven服务器时,出现了上面的报错,如图所示;
详细信息如下:
Execution failed for task ':demo01:publishMavenPublicationToMaven3Repository'.
> Failed to publish publication 'maven' to repository 'maven3'
> Could not PUT 'http://localhost:8082/repository/repos0-snapshot/com/example/demo01/maven-sample/1.6.2/maven-sample-1.6.2.aar'. Received status code 400 from server: Repository version policy: SNAPSHOT does not allow version: 1.6.2
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
原因是配置版本信息version时少了“-SNAPSHOT”后缀;加上就好了
publishing {
publications {
maven(MavenPublication) {
groupId = 'com.example.demo01'
artifactId = 'maven-sample'
version = '1.6.2-SNAPSHOT'
artifact('build/outputs/aar/demo01-debug.aar')
//from components.java
}
}
repositories {
// 本地仓库位于USER_HOME/.m2/repository
//
//mavenLocal()
// 其他maven仓库
maven { url uri('../repository') }
maven {
// change to point to your repo, e.g. http://my.org/repo
url = "$buildDir/repo"
}
// 仓库
// maven {
// allowInsecureProtocol = true
//
// // 凭证
// credentials {
// username 'admin' // 仓库发布用户名
// password 'admin123' // 仓库发布用户密码
// }
// // 地址
// url 'http://localhost:8082/repository/repos0/'
// }
// snapshot仓库
maven {
allowInsecureProtocol = true
// 凭证
credentials {
username 'admin' // 仓库发布用户名
password 'admin123' // 仓库发布用户密码
}
// 地址
url 'http://localhost:8082/repository/repos0-snapshot/'
}
}
}
整个配置文件如下 :
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'maven-publish'
}
android {
compileSdk 32
defaultConfig {
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
//repositories {
// maven {
// allowInsecureProtocol = true
// //allowInsecureProtocol(true)
// url 'http://localhost:8082/service/rest/repository/browse/repos0/'
// }
//}
dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
def coreAarFile = file('build/outputs/aar/demo01-debug.aar')//aar路径
artifacts {
archives coreAarFile
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'com.example.demo01'
artifactId = 'maven-sample'
version = '1.6.2-SNAPSHOT'
artifact('build/outputs/aar/demo01-debug.aar')
//from components.java
}
}
repositories {
// 本地仓库位于USER_HOME/.m2/repository
//
//mavenLocal()
// 其他maven仓库
maven { url uri('../repository') }
maven {
// change to point to your repo, e.g. http://my.org/repo
url = "$buildDir/repo"
}
// 仓库
// maven {
// allowInsecureProtocol = true
//
// // 凭证
// credentials {
// username 'admin' // 仓库发布用户名
// password 'admin123' // 仓库发布用户密码
// }
// // 地址
// url 'http://localhost:8082/repository/repos0/'
// }
// snapshot仓库
maven {
allowInsecureProtocol = true
// 凭证
credentials {
username 'admin' // 仓库发布用户名
password 'admin123' // 仓库发布用户密码
}
// 地址
url 'http://localhost:8082/repository/repos0-snapshot/'
}
}
}