问题
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:
Create repository in bitbucket.
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)
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
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 } } }
Go to module folder, open build.gradle file and paste below line to it
apply from: '../publish-bitbucket.gradle'
Now you can run gradle task with the name "uploadArchives" to deploy aar file to bitbucket.
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" } } }
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