Skip to content

Instantly share code, notes, and snippets.

@gybin02
Created July 19, 2018 05:15
Show Gist options
  • Save gybin02/401241032a0383f44165dbc1f03aac9f to your computer and use it in GitHub Desktop.
Save gybin02/401241032a0383f44165dbc1f03aac9f to your computer and use it in GitHub Desktop.
gradle 打包到Maven
apply plugin: 'maven'
//apply plugin: 'com.github.dcendents.android-maven'
repositories {
mavenCentral()
}
//for project dependency
project.group = GROUP_ID
project.version = COMPONENT_VERSION
task deploy {
}
deploy.dependsOn uploadArchives
uploadArchives {
def typePattern = ~"[0-9]\\.[0-9]\\.[0-9]\$"
def depolyTypeUrl
if(typePattern.matcher(COMPONENT_VERSION)){
println "warn ! find release version! will deploy release aar! version is $COMPONENT_VERSION "
depolyTypeUrl= deployUrl.replace("snapshots","releases")
}else {
depolyTypeUrl = deployUrl
}
// depolyTypeUrl= deployUrl.replace("snapshots","releases")
//println "depolyTypeUrl " + depolyTypeUrl
repositories.mavenDeployer {
repository(url: depolyTypeUrl) {
authentication(userName: deployUserName, password: deployPassword)
}
pom.project {
groupId GROUP_ID
artifactId POM_ARTIFACT_ID
packaging PACKAGE_FORMAT
version COMPONENT_VERSION
}
}
}
//上传源代码
//task androidSourcesJar(type: Jar) {
// classifier = 'sources'
// from android.sourceSets.main.java.sourceFiles
//}
//artifacts {
// archives androidSourcesJar
//}
@gybin02
Copy link
Author

gybin02 commented Jul 19, 2018

1. mvn.gradle 文件放在Project同级目录

wx20180719-132456 2x

2. 修改库工程的Grade.properties文件,如果所示。新增 POM_ARTIFACT_ID 、GROUP_ID、COMPONENT_VERSION配置

wx20180719-132432 2x

3. 修改 同目录下build.gradle,在文件最末尾加上

apply from: "../mvn.gradle"

4. 在Gradle视图中可以 就可以看到 uploadArchives 任务,双击运行。在Log那边可以看到 任务执行情况。

wx20180719-132311 2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment