【问题标题】:Publish android library to nexus with gradle使用 gradle 将 android 库发布到 nexus
【发布时间】:2014-03-26 02:26:44
【问题描述】:

我正在尝试使用 gradle 将我的 android 库发布到 nexus,以便其他人可以使用该代码。但它不起作用并返回错误消息:

> Could not publish configuration 'archives'

java.io.IOException:无法 PUT http://my-server/nexus/content/repositories/snapsho ts/TestLib/testlibdemo/unspecified/testlibdemo-unspecified.aar。从服务器收到状态码 400: 错误的请求

gradle 是否支持将 aar 发布到 Maven Central?

我是 gradle 的菜鸟。这是我的构建文件。

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:0.9.+'
}
}

apply plugin: 'maven'
apply plugin: 'android-library'


repositories {
mavenCentral()
flatDir name: "dist", dirs: "dist"
}

android {
compileSdkVersion 19
buildToolsVersion "19.0.0"

defaultConfig {
    minSdkVersion 8
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
}

dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}

uploadArchives {
repositories {
    maven {
        credentials {
            username "admin"
            password "admin123"
        }
        url "http://myserver/nexus/content/repositories/snapshots"
    }
}
}

【问题讨论】:

    标签: android maven gradle


    【解决方案1】:

    我不确定这是否与 Android 有关,但对于普通的旧 Java,我需要添加以下内容以使用 http 部署到 Nexus 存储库。

    configurations {
        deployJars
    }
    
    dependencies {
        deployJars "org.apache.maven.wagon:wagon-http:2.2"
    }
    

    我在我的顶级 build.gradle 的子项目中有这个,用于多项目构建。

    我的 uploadArchives 看起来也和你的略有不同

    uploadArchives {
        repositories.mavenDeployer {
            repository (url: "<repository url>") {
                authentication(userName: "<username>", password: "<password>")
            }
        }
    }
    

    实际上,我将 中的项目作为 gradle.properties 文件中的属性,因此我可以在命令行上覆盖它们,特别是用户名和密码。这样,当我从 Team City 构建时,我不会将我的凭据嵌入到同事可以看到的文件中。 Team City 允许我将这些值存储为显示为 ** 的构建变量。

    【讨论】:

      猜你喜欢
      • 2017-05-11
      • 1970-01-01
      • 2022-08-21
      • 1970-01-01
      • 2015-01-25
      • 2016-01-13
      • 2015-04-22
      • 2022-06-16
      • 2013-10-18
      相关资源
      最近更新 更多