Received status code 400 from server: Repository version policy: SNAPSHOT does not allow version: 1.

59 篇文章 0 订阅

今天搭建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/'
        }
    }
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值