aboutsummaryrefslogtreecommitdiff
path: root/publish.gradle
blob: 7d8a319a71916c9ec62bc14d2066c5bf76523cff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
apply plugin: 'signing'

def getVersion() {
    if (project.has("release")) {
        return project.ext.baseVersion
    }

    return project.ext.baseVersion + '-SNAPSHOT'
}

version = getVersion()

task publishLocal(type: Upload) {
    configuration = configurations.archives
    repositories {
        mavenDeployer {
            repository(url: uri("$rootProject.ext.androidHostOut/repo"))
        }
    }
}

project.ext.sonatypeUsername = hasProperty('sonatypeUsername') ? sonatypeUsername : ""
project.ext.sonatypePassword = hasProperty('sonatypePassword') ? sonatypePassword : ""

uploadArchives {
    repositories {
        mavenDeployer {
            beforeDeployment { MavenDeployment deployment ->
                if (!project.has("release")) {
                    throw new StopExecutionException("uploadArchives must be called with the release.gradle init script")
                }

                if (project.ext.sonatypeUsername.length() == 0 || project.ext.sonatypePassword.length() == 0) {
                    throw new StopExecutionException("uploadArchives cannot be called without sonatype username and password")
                }

                signing.signPom(deployment)
            }

            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
                authentication(userName: project.ext.sonatypeUsername, password: project.ext.sonatypePassword)
            }

            pom.project {
                name project.ext.pomName
                description project.ext.pomDesc
                url 'http://tools.android.com'
                inceptionYear '2007'

                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        distribution 'repo'
                    }
                }

                scm {
                    url 'https://android.googlesource.com/platform/tools/build'
                    connection 'git://android.googlesource.com/platform/tools/build.git'
                }
                developers {
                    developer {
                        name 'The Android Open Source Project'
                    }
                }
            }
        }
    }
}

// custom tasks for creating source/javadoc jars
task sourcesJar(type: Jar, dependsOn:classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

// add source jar tasks as artifacts
artifacts {
    archives jar
    archives sourcesJar
}

signing {
    required { project.has("release") && gradle.taskGraph.hasTask("uploadArchives") }
    sign configurations.archives
}