xref: /aosp_15_r20/external/conscrypt/gradle/publishing.gradle (revision cd0cc2e34ba52cdf454361820a14d744e4bd531d)
1apply plugin: 'maven-publish'
2apply plugin: 'signing'
3
4def isSnapshot = project.version.contains('SNAPSHOT')
5def isReleaseVersion = !isSnapshot
6
7publishing {
8    publications {
9        maven(MavenPublication) {
10            pom {
11                afterEvaluate {
12                    name = "$project.group:$project.name" as String
13                    description = project.description
14                }
15
16                url = 'https://conscrypt.org/'
17
18                scm {
19                    connection = 'scm:git:https://github.com/google/conscrypt.git'
20                    developerConnection = 'scm:git:[email protected]:google/conscrypt.git'
21                    url = 'https://github.com/google/conscrypt'
22                }
23
24                licenses {
25                    license {
26                        name = 'Apache 2'
27                        url = 'https://www.apache.org/licenses/LICENSE-2.0'
28                    }
29                }
30
31                developers {
32                    developer {
33                        id = 'conscrypt'
34                        name = 'Conscrypt Contributors'
35                        email = '[email protected]'
36                        url = 'https://conscrypt.org/'
37                        organization = 'Google, Inc.'
38                        organizationUrl = 'https://www.google.com'
39                    }
40                }
41            }
42        }
43    }
44
45    repositories {
46        maven {
47            def snapshotUrl = 'https://oss.sonatype.org/content/repositories/snapshots/'
48            def stagingUrl = rootProject.hasProperty('repositoryId') ? \
49                'https://oss.sonatype.org/service/local/staging/deployByRepositoryId/' \
50                    + rootProject.repositoryId : \
51                'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
52            url isSnapshot ? snapshotUrl : stagingUrl
53            credentials {
54                username = rootProject.findProperty('ossrhUsername') ?: ''
55                password = rootProject.findProperty('ossrhPassword') ?: ''
56            }
57        }
58    }
59}
60
61signing {
62    required { isReleaseVersion && gradle.taskGraph.hasTask("publish") }
63    sign publishing.publications.maven
64}
65
66signMavenPublication.doFirst {
67    publishing.publications.maven.artifacts.each {
68        if (it.file.absolutePath.endsWith('.jar') && it.classifier != 'sources' && it.classifier != 'javadoc') {
69            logger.info("Signing jar: ${it.file.absolutePath}")
70            signJar(it.file.absolutePath)
71        }
72   }
73}
74
75tasks.withType(Sign) {
76    onlyIf { isReleaseVersion }
77}
78