Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wagon-git and Gradle

Tags:

git

maven

gradle

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>
like image 602
Jes Chergui Avatar asked Jun 13 '14 14:06

Jes Chergui


2 Answers

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)
}
like image 106
afathman Avatar answered Sep 22 '22 00:09

afathman


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://[email protected]:' + 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!

like image 29
Danh Nguyen Avatar answered Sep 20 '22 00:09

Danh Nguyen