关闭

将Gradle项目发布到maven仓库

995人阅读 评论(0) 收藏 举报
分类:

将Gradle项目发布到maven仓库

1 Gradle简介

1.1 Ant、Maven还是Gradle?

1.1.1 Ant和Maven介绍

全称为Apache Maven,是一个软件(特别是Java软件)项目管理及自动构建工具,由Apache软件基金会所提供。

 在发布maven之前,Android普遍使用ant的方式进行项目的构建和管理,它们均使用XML文件来配置描述项目的,相比较于ant maven提供的功能更加强大。主要表现在以下几点: 
- 使用POM的方式来管理和描述项目 
- 内置了更多的隐式规则,使得构建文件更简单 
- 内置了软件构建的生命周期 
内置了依赖管理来和Repository来实现依赖管理

 然而在一些中大型项目中使用Maven方式构建软件会让XML配置文件越来越大,越来越笨重,而且灵活性不够,因此,出现了gradle.

1.1.2 Gradle

Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化建构工具。它使用一种基于Groovy的特定领域语言来声明项目设置。

 很明显,Gradle的出现是为了弥补ant和maven构建方式的不足,它不是采用传统的xml文件构建方式,而是采用groovy方式来构建。具体映射到android中就是使用gradle脚本文件的构建方式。它贯穿了项目的整个生命周期,包括编译、检查、测试、打包、部署。

 因此,google将gradle方式作为了android项目管理的默认方式,使用android studio创建的项目下面会默认生成build.gradle文件作为默认构建。 
更多的android Gradle介绍请看: 
gradle-android 
wikipedia-gradle介绍 
ant\maven\gradle比较

1.2.常见的Maven仓库和Gradle依赖的使用

 在使用ant构建项目的时候我们要使用第三方库往往要下载对应的库并将其jar文件拷贝到项目文件夹下面,这样会显得很麻烦。在使用gradle构建方式以后我们只要需要一个坐标就能够引入项目库文件,例如:

<code class="hljs rust has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">dependencies {
    compile fileTree(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">dir</span>: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'libs'</span>, include: [<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'*.jar'</span>])
    compile <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'com.android.support:appcompat-v7:22.1.1'</span>
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul>

 这个就是gradle依赖使用方式。所谓的gradle依赖就是我们提供一个坐标然后它会自动帮我们从网络上下载对应的文件,甚至我们可以在本地看到库文件的源码。 
那我们到底是从哪里下载到对应的文件呢?我们通过跟踪项目文件顶级目录下面的buidle gradle文件:

<code class="hljs mathematica has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">allprojects <span class="hljs-list" style="box-sizing: border-box;">{
    repositories {
        jcenter()
    }</span>
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li></ul>

jcenter函数:

<code class="language-java hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">   <span class="hljs-javadoc" style="color: rgb(136, 0, 0); box-sizing: border-box;">/**
     * Adds a repository which looks in Bintray's JCenter repository for dependencies.
     * <p>
     * The URL used to access this repository is {@literal "https://jcenter.bintray.com/"}.
     * The behavior of this repository is otherwise the same as those added by {@link #maven(org.gradle.api.Action)}.
     * <p>
     * Examples:
     * <pre autoTested="">
     * repositories {
     *     jcenter()
     * }
     * </pre>
     *
     *<span class="hljs-javadoctag" style="color: rgb(102, 0, 102); box-sizing: border-box;"> @return</span> the added resolver
     *<span class="hljs-javadoctag" style="color: rgb(102, 0, 102); box-sizing: border-box;"> @see</span> #jcenter(Action)
     */</span>
    MavenArtifactRepository jcenter();</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li></ul>

 我们知道我们的包是从一个叫做Bintray’s JCenter repository中下载而来的,我们打开jcenter库试试, 
这里写图片描述

 看到了我们常见的一些库,这样我终于搞清楚gradle依赖是从哪里来的了。 
 事实上,这个Jcenter库是一家叫做bintray的机构维护,它作为google android官方默认的中央库.但在android studio的早期版本中默认使用的是maven库,它是由sonatype机构维护的。目前主要存在的三个依赖库为:

库名 维护机构 android studio调用
jcenter bintray jcenter()
maven sonatype mavenCentral()
lvy sonatype //一般在ant中使用

三者都是基于Apache Maven的规则来进行依赖。

1.3 aar库文件

 aar文件其实和jar文件作用是一样的,唯一的区别在于aar是专门针对android项目优化过的jar文件,里面除了jar以外还包括了res\string等资源文件。

2 将项目发布到Jcenter Maven仓库中

2.1 发布Jcenter步骤

2.1.1 注册bintray帐号

 为了让自己的项目也能够被全世界的开发者使用,我们可以通过将lib项目发布到jcenter库中,在配置脚本之前我们需要先去官网注册一个帐号,传送门:bintray 也可以使用第三方登录的方式来登录,包括github、google、facebook帐号等。注册成功后我们先要获取到一个api key。 
这里写图片描述

2.1.2 上传文件

 在Jcenter库中要求上传到库中的项目必须包含4个文件: 
  - javadoc.jar 
  - sources.jar 
  - aar或者jar 
  - pom 
 如果少了审核可能不会通过,当然这几个文件都可一通过配置gradle脚本来自动生成。

2.2 配置Gradle脚本

 为了创建上面所说的几个文件,我们需要构建脚本来自动生成对应的文件。具体可以参考:github-SwipeView-build.gradle

2.2.1 配置项目依赖

将项目文件根目录(Top-level)下面的buide.gradle文件增加依赖:

<code class="hljs lua has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> dependencies {
        classpath <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'com.android.tools.build:gradle:1.0.0'</span>
        classpath <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'com.github.dcendents:android-maven-plugin:1.2'</span>
        classpath <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'</span>

        // NOTE: Do <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">not</span> place your application dependencies here; they belong
        // <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> the individual <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">module</span> build.gradle files
    }</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li></ul>

注意: classpath ‘com.android.tools.build:gradle:1.0.0’ 在默认生成的文件下可能版本不一致,采用默认的有时候会导致构建失败,最好也修改成1.0.0版本的。

2.2.2 增加gradle插件和版本号

 在需要上传的library项目的build.gradle下增加插件引用和版本号:

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">apply plugin: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'com.android.library'</span>
apply plugin: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'com.github.dcendents.android-maven'</span>
apply plugin: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'com.jfrog.bintray'</span>
<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">version</span> = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"1.0"</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li></ul>

注意:版本号作为项目坐标的一部分,以后在升级项目的时候都需要升级版本号,否则会覆盖掉已经上传的版本. 
 关于插件bintray的更详细的使用方式可以查看:github-bintray

2.2.3 pom节点生成

 生成POM文件build脚本

<code class="hljs scala has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">def</span> siteUrl = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'https://github.com/daliyan/SwipeView'</span>      <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 项目的主页</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">def</span> gitUrl = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'https://github.com/daliyan/SwipeView.git'</span>   <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// Git仓库的url</span>
group = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"akiyama.swipe"</span>
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 根节点添加</span>
install {
    repositories.mavenInstaller {
        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// This generates POM.xml with proper parameters</span>
        pom {
            project {
                packaging <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'aar'</span>
                name <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'swipeView For Android'</span>
                url siteUrl
                licenses {
                    license {
                        name <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'The Apache Software License, Version 2.0'</span>
                        url <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'http://www.apache.org/licenses/LICENSE-2.0.txt'</span>
                    }
                }
                developers {
                    developer {
                        id <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'akiyama'</span>
                        name <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'daliyan'</span>
                        email <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'dali_yan@yeah.net'</span>
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl
                }
            }
        }
    }
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li></ul>

注意:group = “akiyama.swipe”作为项目坐标的前缀,packaging ‘aar’ 为arr包,其它的自己随意填写。

2.2.4 javadoc和sources文件的生成

 添加生成任务:

<code class="hljs haskell has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-title" style="box-sizing: border-box;">task</span> sourcesJar(<span class="hljs-typedef" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">type</span>: <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Jar</span>) <span class="hljs-container" style="box-sizing: border-box;">{
    <span class="hljs-title" style="box-sizing: border-box;">from</span> <span class="hljs-title" style="box-sizing: border-box;">android</span>.<span class="hljs-title" style="box-sizing: border-box;">sourceSets</span>.<span class="hljs-title" style="box-sizing: border-box;">main</span>.<span class="hljs-title" style="box-sizing: border-box;">java</span>.<span class="hljs-title" style="box-sizing: border-box;">srcDirs</span>
    <span class="hljs-title" style="box-sizing: border-box;">classifier</span> = '<span class="hljs-title" style="box-sizing: border-box;">sources'</span>
}</span></span>

<span class="hljs-title" style="box-sizing: border-box;">task</span> javadoc(<span class="hljs-typedef" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">type</span>: <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Javadoc</span>) <span class="hljs-container" style="box-sizing: border-box;">{
    <span class="hljs-title" style="box-sizing: border-box;">source</span> = <span class="hljs-title" style="box-sizing: border-box;">android</span>.<span class="hljs-title" style="box-sizing: border-box;">sourceSets</span>.<span class="hljs-title" style="box-sizing: border-box;">main</span>.<span class="hljs-title" style="box-sizing: border-box;">java</span>.<span class="hljs-title" style="box-sizing: border-box;">srcDirs</span>
    <span class="hljs-title" style="box-sizing: border-box;">classpath</span> += <span class="hljs-title" style="box-sizing: border-box;">project</span>.<span class="hljs-title" style="box-sizing: border-box;">files</span>(<span class="hljs-title" style="box-sizing: border-box;">android</span>.<span class="hljs-title" style="box-sizing: border-box;">getBootClasspath</span>().<span class="hljs-title" style="box-sizing: border-box;">join</span>(<span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">File</span>.<span class="hljs-title" style="box-sizing: border-box;">pathSeparator</span>))
}</span></span>

<span class="hljs-title" style="box-sizing: border-box;">task</span> javadocJar(<span class="hljs-typedef" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">type</span>: <span class="hljs-type" style="box-sizing: border-box; color: rgb(102, 0, 102);">Jar</span>, dependsOn: javadoc) <span class="hljs-container" style="box-sizing: border-box;">{
    <span class="hljs-title" style="box-sizing: border-box;">classifier</span> = '<span class="hljs-title" style="box-sizing: border-box;">javadoc'</span>
    <span class="hljs-title" style="box-sizing: border-box;">from</span> <span class="hljs-title" style="box-sizing: border-box;">javadoc</span>.<span class="hljs-title" style="box-sizing: border-box;">destinationDir</span>
}</span></span>

<span class="hljs-title" style="box-sizing: border-box;">artifacts</span> {
    archives javadocJar
    archives sourcesJar
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li></ul>

注意:在构建生成的时候有可能会报GBK编码等错误,可能需要添加UTF-8声明,如下:

<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//添加UTF-8编码否则注释可能JAVADOC文档可能生成不了</span>
javadoc {
    options{
        encoding <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"UTF-8"</span>
        charSet <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'UTF-8'</span>
        author <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>
        version <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>
        links <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"http://docs.oracle.com/javase/7/docs/api"</span>
        title <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"swipeJavaDoc"</span>
    }
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li></ul>
2.2.5 构建上传jecnter库中脚本

 使用前面的我们注册帐号和apikey上传对应的文件到jcenter库中:

<code class="hljs sql has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">Properties properties = new Properties()
properties.<span class="hljs-operator" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">load</span>(project.rootProject.file(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'local.properties'</span>).newDataInputStream())
bintray {
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">user</span> = properties.getProperty(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"bintray.user"</span>)
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">key</span> = properties.getProperty(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"bintray.apikey"</span>)
    configurations = [<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'archives'</span>]
    pkg {
        repo = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"maven"</span>
        name = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"swipeView"</span>                // project name <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">in</span> jcenter
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = [<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Apache-2.0"</span>]
        publish = <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">true</span>
    }
}</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li></ul>

 因为用户名和apikey是属于个人的隐私信息,故在local.properties(该文件不会上传到git库中)本地文件中配置用户名和apikey

<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sdk<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.dir</span>=/home/android-sdk
bintray<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.user</span>=your username
bintray<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.apikey</span>=your apikey</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

2.3 上传和审核

在配置好了上述build.gradle文件后我们打开gradle控制面板就能看到如图所示的构建任务: 
这里写图片描述

这里写图片描述

我们只需要双击bintrayUpload就能自动上传到jcenter库中了。 
到官网找到我们刚刚上传的文件,提交审核就行了(别跟我说你找不到),一般2-3个小时就能审核成功。 
成功后可以通过http://jcenter.bintray.com/ 查询到你的库文件,例如我的项目文件路径为:http://jcenter.bintray.com/akiyama/swipe/library/2.1

2.4 同步项目到mvnrepository

在jcenter中提供了将项目同步到mvnrepository库中,这样就不需要操作上传到mvnrepository库的繁琐步骤。在bintray构建脚本最后加上:

<code class="hljs coffeescript has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span>Optional configuration <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> Maven Central sync <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">of</span> the version
            mavenCentralSync {
                sync = <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">true</span> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span>Optional (<span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">true</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">by</span> <span class="hljs-reserved" style="box-sizing: border-box;">default</span>). Determines whether to sync the version to Maven Central.
                user = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'userToken'</span> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span>OSS user token
                password = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'paasword'</span> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span>OSS user password
                close = <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'1'</span> <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span>Optional property. By <span class="hljs-reserved" style="box-sizing: border-box;">default</span> the staging repository <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">is</span> closed <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">and</span> artifacts are released to Maven Central. You can optionally turn <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">this</span> behaviour <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">off</span> (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">by</span> puting <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> as value) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">and</span> release the version manually.
            } </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>

注意:user和password即为mvnrepository中注册的用户名和密码。如果同步成功你也可以通过http://mvnrepository.com/ 查询到你上传的lib项目

2.5 常见问题

在构建脚本过程中可能会出现一些问题: 
- GBK编码问题,前文已经提供了解决方案; 
- 依赖库问题,可能会报告一些警告,只要保证最后构建成功,直接忽略即可; 
- gradle依赖问题:可以参照githug-bintray 解决方案: 
Gradle >= 2.1

<code class="hljs applescript has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">plugins {
    <span class="hljs-property" style="box-sizing: border-box;">id</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"com.jfrog.bintray"</span> <span class="hljs-property" style="box-sizing: border-box;">version</span> <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"1.3.1"</span>
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

Gradle < 2.1

<code class="hljs matlab has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">buildscript <span class="hljs-cell" style="box-sizing: border-box;">{
    repositories {
        jcenter()
    }</span>
    dependencies <span class="hljs-cell" style="box-sizing: border-box;">{
        classpath <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3.1'</span>
    }</span>
}
apply plugin: <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'com.jfrog.bintray'</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li></ul>

3 小结

本文学习了gradle的一些基本知识和基本的构建,学习了如何将lib库上传到中央仓库中,以及在这个过程中可能遇到的问题。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:224087次
    • 积分:3180
    • 等级:
    • 排名:第10777名
    • 原创:98篇
    • 转载:29篇
    • 译文:0篇
    • 评论:64条
    最新评论