【问题标题】:wagon-git and Gradlewagon-git 和 Gradle
【发布时间】:2014-06-13 14:41:22
【问题描述】:

这个不错的小工具承诺帮助我将工件上传到私人 Bitbucket 存储库。

http://synergian.github.io/wagon-git/bitbucket.html

我在我的 Gradle 构建中使用本指南时遇到问题...

我发现了这个简短而有限的例子, https://github.com/UniconLabs/ssl-utils/blob/master/build.gradle

对我来说最不清楚的是关于如何在我的 Maven 主页中准备 settings.xml 的部分。我应该使用我的 .gradle 文件夹,因为我使用的是 Gradle 吗?

Bitbucket 私有存储库

以同样的方式进行,但在 Maven 中添加基本身份验证 settings.xml(通常位于您的 $MAVEN_HOME 目录中,请查看 http://maven.apache.org/settings.html 获取完整指南)。

<settings>
        ...
        <servers>
                <server>
                        <id>your-repo-id</id>
                        <username>yourbitbucketusername</username>
                        <password>yourbitbucketpassword</password>
                </server>
                ...
        </servers>
        ...
</settings>

【问题讨论】:

    标签: git maven gradle


    【解决方案1】:

    最简单的做法是转到您的 ~/.gradle/gradle.properties 文件,然后添加以下两行:

    yourbitbucketusername = [bitbucket username]
    yourbitbucketpassword  = [bitbucket password]
    

    然后您可以在 build.gradle 中添加以下内容:

    uploadArchives {
        repositories {
            mavenDeployer {
            repository(url: "repo url") {
            authentication(userName: yourbitbucketusername, 
                    password: yourbitbucketpassword)
    }
    

    【讨论】:

      【解决方案2】:

      我使它与下面的脚本一起工作,但在此之前您需要按照以下步骤操作:

      1. 在 bitbucket 中创建存储库。

      2. 创建 ssh 密钥并添加到您的 bitbucket 帐户。 (记得将你的密钥文件保存在 ~/.ssh/ 文件夹中。(看起来像 wagon-git 总是在这里搜索你的密钥)

      3. 创建 gradle.properties 文件来配置所需的变量。

        COMPANY = `user name or team or company`
        REPOSITORY_NAME = `repository name on bitbucket`
        ARTIFACT_PACKAGE = `com.company.package.id`
        ARTIFACT_VERSION = 1.0.0
        ARTIFACT_NAME= `library name`
        ARTIFACT_PACKAGING = aar
        
      4. 在项目文件夹中创建一个名为“publish-bitbucket.gradle”的 gradle 文件。复制并粘贴以下代码。

        apply plugin: 'maven'
        
        repositories {
            maven { url "https://raw.github.com/synergian/wagon-git/releases" }
        }
        
        configurations {
            deployLibrary
        }
        
        dependencies {
            implementation fileTree(dir: 'libs', include: ['*.jar'])
            deployLibrary "ar.com.synergian:wagon-git:0.2.5"
        }
        
        uploadArchives {
        
            repositories.mavenDeployer {
                configuration = configurations.deployLibrary
                repository(url: 'git:master://git@bitbucket.org:' + COMPANY + '/' + REPOSITORY_NAME + '.git')
                pom.project {
                    groupId = ARTIFACT_PACKAGE
                    version = ARTIFACT_VERSION
                    artifactId = ARTIFACT_NAME
                    packaging ARTIFACT_PACKAGING
                }
            }
        }
        
      5. 转到模块文件夹,打开 build.gradle 文件并将下面的行粘贴到它

        apply from: '../publish-bitbucket.gradle'
        
      6. 现在您可以运行名为“uploadArchives”的 gradle 任务,将 aar 文件部署到 bitbucket。

      7. 从 android studio 中引用库。将如下的 maven 配置添加到您的项目 build.gradle 文件中。

        allprojects {
            repositories {
                google()
                jcenter()
        
                maven {
                    url 'https://maven.google.com/'
                }
        
                maven {
                    credentials {
                        username "bitbucket user name"
                        password "generated personal app password"
                    }
        
                    authentication {
                        basic(BasicAuthentication)
                    }
        
                    url "https://api.bitbucket.org/2.0/repositories/`user name or team`/`repository name`/src/master"
                }
            }
        }
        
      8. 在模块 build.gradle 文件中。使用下面的格式来实现库。

        implementation(group: 'com.company.app.id', name: 'module name', version: '1.0.0', ext: 'aar')
        

      我尝试更正代码格式以在我的答案中正确显示,但是当我粘贴 gradle 代码时看起来很难更正它。希望对您有所帮助!

      【讨论】:

        【解决方案3】:

        为了避免bitbucket认证的问题和可能通过gradle泄露密码的问题,我只是简单的发布到本地git repo,然后手动push到bitbucket。

        【讨论】:

          猜你喜欢
          • 2014-09-30
          • 1970-01-01
          • 2010-10-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-07-08
          相关资源
          最近更新 更多