gradle maven私服构建aar

来源:互联网 发布:java获取小数点后两位 编辑:程序博客网 时间:2024/05/17 13:10

 gradle  对maven仓库的依赖非常好,所以在使用aar之前,需要将aar上传到maven仓库中,(一般都是部门自己搭建的私有maven仓库,如何搭建此处跳过)。 

1.首先构建push的gradle 脚本  xxx-gradle-mvn-push.gradle


apply plugin: 'maven'apply plugin: 'signing'def isReleaseBuild() {    return VERSION_NAME.contains("SNAPSHOT") == false}def getReleaseRepositoryUrl() {    return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL :            'http://172.16.49.190:8081/nexus/content/repositories/xxx-android-release/'}def getSnapshotRepositoryUrl() {    return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL :            'http://172.16.49.190:8081/nexus/content/repositories/xxx-android-snapshot/'}def getRepositoryUsername() {    return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ''}def getRepositoryPassword() {    return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ''}afterEvaluate { project ->    uploadArchives {        repositories {            mavenDeployer {                beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }                pom.groupId = POM_GROUP_ID                pom.artifactId = POM_ARTIFACT_ID                pom.version = VERSION_NAME                pom.packaging = POM_PACKAGING                repository(url: getReleaseRepositoryUrl()) {                    authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())                }                snapshotRepository(url: getSnapshotRepositoryUrl()) {                    authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())                }                pom.project {                    name POM_NAME                    description POM_DESCRIPTION                    licenses {                        license {                            name POM_LICENCE_NAME                            url POM_LICENCE_URL                            distribution POM_LICENCE_DIST                        }                    }                    developers {                        developer {                            name POM_DEVELOPER_NAME                            id POM_DEVELOPER_ID                            email POM_DEVELOPER_EMAIL                        }                    }                }            }        }    }    signing {        required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }        sign configurations.archives    }    task sourceCode(type: Zip) {        appendix = extension = 'src'        from 'AndroidManifest.xml'        into('res') {            from 'res'        }        into('src') {            from 'src'        }        into('libs') {            from 'libs'        }    }    task androidJavadocs(type: Javadoc) {        source = android.sourceSets.main.java.srcDirs        ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"        classpath += files(ext.androidJar)    }    task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {        classifier = 'javadoc'        from androidJavadocs.destinationDir    }    task androidSourcesJar(type: Jar) {        classifier = 'sources'        from android.sourceSets.main.java.sourceFiles    }    artifacts {        archives sourceCode        archives androidSourcesJar        archives androidJavadocsJar    }}


2.gradle.properties配置pom以及Setting(这里从我的工程上copy示例,标签大家自己去查,就不一一注释了)

# POMject-wide Gradle settings.# IDE (e.g. Android Studio) users:# Gradle settings configured through the IDE *will override*# any settings specified in this file.# For more details on how to configure your build environment visit# http://www.gradle.org/docs/current/userguide/build_environment.html# Default value: -Xmx1024m -XX:MaxPermSize=256m# Specifies the JVM arguments used for the daemon POMcess.# The setting is particularly useful for tweaking memory settings.# When configured, Gradle will run in incubating parallel mode.# This option should only be used with decoupled POMjects. More details, visit# http://www.gradle.org/docs/current/userguide/multi_POMject_builds.html#sec:decoupled_POMjects# gradle build setting# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8# org.gradle.configureondemand=true# org.gradle.parallel=true# org.gradle.daemon=true# android.useDeprecatedNdk=true# Android build settingBUILD_MIN_SDK_VERSION=9BUILD_TARGET_SDK_VERSION=23BUILD_SDK_VERSION=23BUILD_TOOLS_VERSION=23.0.1# Nexus maven setting#signing.keyId=XXXXXXXXX#signing.password=XXXXXXXXX#signing.secretKeyRingFile=/Users/.../secring.gpgNEXUS_USERNAME=xxxNEXUS_PASSWORD=xxx#NEXUS_USERNAME=xxx#NEXUS_PASSWORD=xxx#VERSION_NAME=2.1.2VERSION_NAME=2.1.9-SNAPSHOTVERSION_CODE=152POM_GROUP_ID=xxxPOM_ARTIFACT_ID=xxxPOM_PACKAGING=aarPOM_NAME=xxxPOM_DESCRIPTION=xx base dependences library to android program.POM_LICENCE_NAME=The Apache Software License, Version 2.0POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txtPOM_LICENCE_DIST=xxxPOM_DEVELOPER_ID=xxxPOM_DEVELOPER_NAME=xxxPOM_DEVELOPER_EMAIL=xxx


3.在子moudle 的build.gradle中关联刚刚的配置 

apply from: './dfjk-gradle-mvn-push.gradle'


4.执行发布(记得先刷新一下)



5.最后你就可以在新的工程中使用刚才的aar了

  在新工程的build.gradle文件中加上:

    compile 'com.xxx.xxx.'  

1 1
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 渐变区的选择框变得很大怎么办 用乐秀编辑短片后两边有边框怎么办 安卓手机相机图标没有了怎么办 三星s6不充电就死机了怎么办 三星s7通话感应器不管用了怎么办 卡贴苹果8p一直跳激活怎么办? 宝宝添了小狗添过的袋子怎么办 猫咪卡在屋顶的缝隙里怎么办 大臂的图案纹小了怎么办 双面板已经贴片还要插件后焊怎么办 黑板摔在地上有木头屑怎么办 白衣服蓝袖子漂花了怎么办 白衣服泡了一夜袖子发黄怎么办 小孩的胳膊肘关节处摔断开了怎么办 生完孩子以后奶头总有脏东西怎么办 月经有黑乎乎的脏东西下不来怎么办 四季梅叶子打卷花从粉变白怎么办 新移栽的竹子出来太细怎么办 土培富贵竹长得太高了怎么办 毛竹加工厂被环保查了该怎么办? 领养姐姐家的孩子怎么办领养手续 孩子喝了点杯子变质发霉的水怎么办 杯子发霉没洗干净喝了水怎么办 小孩的咪咪头没有突出来怎么办 手被竹子刺了肿了怎么办 紫竹刚栽叶子发枯怎么办能活吗 移栽大田的水稻过施了氮肥怎么办 股骨术后六十天有小量骨痂怎么办 被桃树上的蜂蜜咬了怎么办 照片回收站密码找不回来了怎么办 扣扣空间照片回收站密码忘了怎么办 我眼睛近视了不想戴眼镜怎么办 微信聊天对方只回一个字怎么办 大学室友都不是自己喜欢的人怎么办 超轻粘土粘在衣服上怎么办 粽子昨晚煮好今日发现不够熟怎么办 5岁宝宝左眼轻微散光怎么办光 孩子总吸鼻子但没有鼻涕怎么办 纹完眼线眼睛磨的很难受怎么办 我的脸型眼睛好看牙不好看怎么办 陌陌当日打招呼人数已达上限怎么办