Created
March 26, 2018 11:08
-
-
Save mricefox/fe62f19f160ccdcb8b193b169ad87249 to your computer and use it in GitHub Desktop.
Gradle maven push script for android and java, support publish to maven local
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
apply plugin: 'maven' | |
apply plugin: 'signing' | |
version = VERSION_NAME | |
group = GROUP | |
def isReleaseBuild() { | |
return VERSION_NAME.contains("SNAPSHOT") == false | |
} | |
def getReleaseRepositoryUrl() { | |
if (hasProperty('PUBLISH_TO_MAVEN_LOCAL') && Boolean.valueOf(PUBLISH_TO_MAVEN_LOCAL)) { | |
return repositories.mavenLocal().url | |
} | |
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL : "" | |
} | |
def getSnapshotRepositoryUrl() { | |
if (hasProperty('PUBLISH_TO_MAVEN_LOCAL') && Boolean.valueOf(PUBLISH_TO_MAVEN_LOCAL)) { | |
return repositories.mavenLocal().url | |
} | |
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL : "" | |
} | |
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 = GROUP | |
pom.artifactId = POM_ARTIFACT_ID | |
pom.version = VERSION_NAME | |
repository(url: getReleaseRepositoryUrl()) { | |
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) | |
} | |
snapshotRepository(url: getSnapshotRepositoryUrl()) { | |
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) | |
} | |
pom.project { | |
name POM_NAME | |
packaging POM_PACKAGING | |
description POM_DESCRIPTION | |
url POM_URL | |
scm { | |
url POM_SCM_URL | |
connection POM_SCM_CONNECTION | |
developerConnection POM_SCM_DEV_CONNECTION | |
} | |
licenses { | |
license { | |
name POM_LICENCE_NAME | |
url POM_LICENCE_URL | |
distribution POM_LICENCE_DIST | |
} | |
} | |
developers { | |
developer { | |
id POM_DEVELOPER_ID | |
name POM_DEVELOPER_NAME | |
} | |
} | |
} | |
} | |
} | |
} | |
signing { | |
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } | |
sign configurations.archives | |
} | |
if (project.getPlugins().hasPlugin('com.android.application') || | |
project.getPlugins().hasPlugin('com.android.library')) { | |
task install(type: Upload, dependsOn: assemble) { | |
repositories.mavenInstaller { | |
configuration = configurations.archives | |
pom.groupId = GROUP | |
pom.artifactId = POM_ARTIFACT_ID | |
pom.version = VERSION_NAME | |
pom.project { | |
name POM_NAME | |
packaging POM_PACKAGING | |
description POM_DESCRIPTION | |
url POM_URL | |
scm { | |
url POM_SCM_URL | |
connection POM_SCM_CONNECTION | |
developerConnection POM_SCM_DEV_CONNECTION | |
} | |
licenses { | |
license { | |
name POM_LICENCE_NAME | |
url POM_LICENCE_URL | |
distribution POM_LICENCE_DIST | |
} | |
} | |
developers { | |
developer { | |
id POM_DEVELOPER_ID | |
name POM_DEVELOPER_NAME | |
} | |
} | |
} | |
} | |
} | |
task androidJavadocs(type: Javadoc) { | |
failOnError false | |
source = android.sourceSets.main.java.source | |
classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) | |
} | |
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { | |
classifier = 'javadoc' | |
from androidJavadocs.destinationDir | |
} | |
task androidSourcesJar(type: Jar) { | |
classifier = 'sources' | |
from android.sourceSets.main.java.source | |
} | |
} else { | |
install { | |
repositories.mavenInstaller { | |
pom.groupId = GROUP | |
pom.artifactId = POM_ARTIFACT_ID | |
pom.version = VERSION_NAME | |
pom.project { | |
name POM_NAME | |
packaging POM_PACKAGING | |
description POM_DESCRIPTION | |
url POM_URL | |
scm { | |
url POM_SCM_URL | |
connection POM_SCM_CONNECTION | |
developerConnection POM_SCM_DEV_CONNECTION | |
} | |
licenses { | |
license { | |
name POM_LICENCE_NAME | |
url POM_LICENCE_URL | |
distribution POM_LICENCE_DIST | |
} | |
} | |
developers { | |
developer { | |
id POM_DEVELOPER_ID | |
name POM_DEVELOPER_NAME | |
} | |
} | |
} | |
} | |
} | |
task sourcesJar(type: Jar, dependsOn: classes) { | |
classifier = 'sources' | |
from sourceSets.main.allSource | |
} | |
task javadocJar(type: Jar, dependsOn: javadoc) { | |
classifier = 'javadoc' | |
from javadoc.destinationDir | |
} | |
} | |
if (JavaVersion.current().isJava8Compatible()) { | |
allprojects { | |
tasks.withType(Javadoc) { | |
options.addStringOption('Xdoclint:none', '-quiet') | |
} | |
} | |
} | |
artifacts { | |
if (project.getPlugins().hasPlugin('com.android.application') || | |
project.getPlugins().hasPlugin('com.android.library')) { | |
archives androidSourcesJar | |
archives androidJavadocsJar | |
} else { | |
archives sourcesJar | |
archives javadocJar | |
} | |
} | |
} |
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
#Usage of gradle-mvn-push.gradle | |
#Properties of sub project | |
VERSION_NAME = '1.0.0' | |
GROUP = 'com.mricefox.archmage.build.gradle' | |
POM_DESCRIPTION = 'Gradle Plug-in for Archmage.' | |
POM_NAME = 'Gradle Plug-in for Archmage' | |
POM_ARTIFACT_ID = 'archmage-gradle-plugin' | |
POM_PACKAGING = 'jar' | |
PUBLISH_TO_MAVEN_LOCAL=false | |
#Properties of root project | |
POM_URL=https://github.com/MrIceFox/Archmage | |
POM_SCM_URL=https://github.com/MrIceFox/Archmage | |
POM_SCM_CONNECTION=scm:https://github.com/MrIceFox/Archmage.git | |
POM_SCM_DEV_CONNECTION=scm:https://github.com/MrIceFox/Archmage.git | |
POM_LICENCE_NAME=The Apache Software License, Version 2.0 | |
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt | |
POM_LICENCE_DIST=repo | |
POM_DEVELOPER_ID=mricefox | |
POM_DEVELOPER_NAME=Mr.Icefox | |
RELEASE_REPOSITORY_URL = http://xxx.xxx.xxx.xxx:xxx/nexus/content/repositories/releases | |
SNAPSHOT_REPOSITORY_URL = http://xxx.xxx.xxx.xxx:xxx/nexus/content/repositories/snapshots | |
NEXUS_USERNAME=username | |
NEXUS_PASSWORD=password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment