wagon-git and Gradle

喜欢而已 提交于 2021-01-26 18:40:55

问题


This nice little tool promise help me upload artifacts up to a private Bitbucket repo.

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

I am having troubles using this guide in my Gradle build...

I've found this short and limited example, https://github.com/UniconLabs/ssl-utils/blob/master/build.gradle

Most unclear for me is this section about how to prepare the settings.xml inside my maven home. Am I supposed to use my .gradle folder instead since I work with Gradle?

Bitbucket Private Repositories

Proceed the same way, but add basic authentication in your Maven settings.xml (usually located at your $MAVEN_HOME directory, check out http://maven.apache.org/settings.html for a full guide).

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

回答1:


Easiest thing to do is go to your ~/.gradle/gradle.properties file, and add the following two lines:

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

Then you can add the following in your build.gradle:

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



回答2:


i made it work with the script below, but before that you need to follow theses steps:

  1. Create repository in bitbucket.

  2. Create ssh key and add to your bitbucket account. (remember to save your key files in ~/.ssh/ folder. (look like wagon-git always search your key here)

  3. Create gradle.properties file to config required variable.

    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. Create a gradle file with the name is "publish-bitbucket.gradle" in project folder. Copy and paste below code to it.

    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. Go to module folder, open build.gradle file and paste below line to it

    apply from: '../publish-bitbucket.gradle'
    
  6. Now you can run gradle task with the name "uploadArchives" to deploy aar file to bitbucket.

  7. To reference the library from android studio. Add maven configuration like below to your project build.gradle file.

    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. In module build.gradle file. Use below format to implement library.

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

I tried to correct the code format to display right in my answer, but look like too hard to correct it when i pasted in the gradle code. Hope it help!




回答3:


To avoid the questions of bitbucket authentication and possible leak of the password through gradle, I simply publish to a local git repo, and then manually push the commit to bitbucket.



来源:https://stackoverflow.com/questions/24207997/wagon-git-and-gradle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!