Last active
July 9, 2020 08:09
-
-
Save hyongbai/6df8244cd52866149b91ac34740fee13 to your computer and use it in GitHub Desktop.
upload to maven center
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
allprojects[0].repositories.listIterator().toSet().forEach { | |
println("REPOSITORY: ${it.name} ${it.properties.get('url')}") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
println("config uploadArchives.gradle:\n" + | |
" ext.maven_group = \"\"\n" + | |
" ext.maven_version = \"\"\n" + | |
" ext.maven_artifact = \"\"\n" + | |
" ext.maven_remote = \"\"\n" + | |
" ext.maven_user = \"\"\n" + | |
" ext.maven_password = \"\"") | |
if (!project.hasProperty("android")) { | |
// Java libraries | |
task sourcesJar(overwrite: true, type: Jar, dependsOn: classes) { | |
classifier = 'sources' | |
from sourceSets.main.allSource | |
} | |
} else { | |
// Android libraries | |
task sourcesJar(overwrite: true, type: Jar) { | |
classifier = 'sources' | |
from android.sourceSets.main.java.srcDirs | |
} | |
// overwrite javadoc | |
task javadoc(overwrite: true, type: Javadoc) { | |
failOnError false | |
options { | |
links "http://docs.oracle.com/javase/7/docs/api/" | |
linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference" | |
} | |
source = android.sourceSets.main.java.srcDirs | |
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) | |
} | |
} | |
task javadocJar(overwrite: true, type: Jar, dependsOn: javadoc) { | |
classifier = 'javadoc' | |
from javadoc.destinationDir | |
} | |
artifacts { | |
archives javadocJar | |
archives sourcesJar | |
} | |
tasks.withType(JavaCompile) { | |
options.encoding = "UTF-8" | |
} | |
def propOrDefault(prop, defValue) { | |
if (binding.hasVariable(prop)) { | |
return binding.variables.get(prop) | |
} | |
// | |
if (project.hasProperty(prop)) { | |
return project.getProperties().get(prop) | |
} | |
// | |
return defValue | |
} | |
apply plugin: 'maven' | |
uploadArchives { | |
repositories.mavenDeployer { | |
pom.groupId = propOrDefault("maven_group", android.defaultConfig.applicationId) | |
pom.version = propOrDefault("maven_version", android.defaultConfig.versionName) | |
pom.artifactId = propOrDefault("maven_artifact", project.name) | |
} | |
} | |
def uploadBy(name, closure) { | |
tasks.create("_${name}") { doFirst(closure) } | |
tasks.create("${name}") { | |
dependsOn(["_${name}", uploadArchives]) | |
doLast { | |
def divider = { "${1.upto(64) { print '*' }}"; println() } | |
// | |
divider() | |
final def dep = uploadArchives.repositories.mavenDeployer | |
println(">>> ${name} success!!!") | |
println(" api '${dep.pom.groupId}:${dep.pom.artifactId}:${dep.pom.version}'") | |
println(" maven { url '${dep.repository.url}' }") | |
divider() | |
} | |
} | |
} | |
uploadBy("uploadLocal") { | |
uploadArchives.repositories.mavenDeployer { | |
repository(url: propOrDefault("maven_local", "file://${System.getenv('HOME')}/.m2/repository")) | |
// pom.version = "${pom.version}-uploadLocal2" | |
} | |
} | |
uploadBy("uploadRemote") { | |
uploadArchives.repositories.mavenDeployer { | |
repository(url: null) { | |
url = propOrDefault("maven_remote", "http://www.yourmavenserver.com") | |
authentication(userName: "${maven_user}", password: "${maven_password}") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment