发布自己的开源项目

注册地址: https://bintray.com/signup/oss

参考:https://www.jianshu.com/p/d0d39677bf6a
参考:https://github.com/zhxhcoder/XButton

1,个人注册地址: https://bintray.com/signup/oss
最好用gmail邮箱
2,创建一个Maven仓库,Name:为仓库的名字、Type:一定要选择Maven、Default Licenses:选啥都行

3,需要在项目的build.gradle中添加上传的插件,

dependencies{
    //.....
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1'
}

4,在module的build.gradle中

apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

android {
    compileSdkVersion 27

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    android.libraryVariants.all {
        variant ->
            variant.outputs.all {
                outputFileName = "xbutton.aar"
            }
    }
}

this.project.afterEvaluate {
    def buildTask = this.project.tasks.getByName('assembleRelease')
    if (buildTask == null) throw GradleException
    buildTask.doLast {
        copyApk.execute()
    }
}

/** 执行完成打包后将文件复制到主项目的资源文件中*/
task copyApk {
    doLast {
        if (rootProject.file('app/libs/xbutton.aar').exists()) {
            println('我先删除了旧的xbutton.aar')
            rootProject.file('pp/libs/xbutton.aar').delete()
        }
        copy {
            from "${buildDir}/outputs/aar/xbutton.aar"
            into rootProject.file('app/libs/')
            println('新的xbutton.aar已经复制到app/libs/')
        }
    }

}

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

def siteUrl = 'https://github.com/zhxhcoder/XButton'   //项目的主页
def gitUrl = 'https://github.com/zhxhcoder/XButton.git'   //github仓库的地址
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

version = "1.0.0"//version
group = "com.zhxh"//groupId
bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")
    pkg {
        repo = 'android'//创建的仓库名字
        name = 'XButton'//packageName
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ['Apache-2.0']//创建仓库时选择的license type
        userOrg = 'zhuxhcoder' //自己bintray创建的organization名称
        publish = true // 是否是公开项目。

        version {
            name = '1.0.0'//版本号
            desc = 'A extent Button.'//版本描述
            released = new Date()
            vcsTag = 'v1.0'
            attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin']
        }
    }
    configurations = ['archives']
}
install {
    repositories.mavenInstaller {
        pom {
            project {
                packaging 'aar'
                //项目描述
                description 'A extent Button.'
                url siteUrl
                // 填写开源协议
                licenses {
                    license {
                        name 'Apache-2.0'
                        url ' http://www.apache.org/licenses/LICENSE-2.0'
                    }
                }
                developers {
                    developer {
                        id 'geekcoder'
                        //填写邮件地址
                        email '[email protected]'
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl
                }
            }
        }
    }
}
//打包源码
task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}
//打包源码doc文档
task javadoc(type: Javadoc) {
    options.encoding = "UTF-8"
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}
artifacts {
    archives javadocJar
    archives sourcesJar
}

5,运行 gradlew install 和 gradlew brintrayUpload

你可能感兴趣的:(发布自己的开源项目)