|
| 1 | +apply plugin: 'maven-publish' |
| 2 | +apply plugin: 'signing' |
| 3 | +apply from: rootProject.file('publishing.gradle') |
| 4 | + |
| 5 | +if (project.hasProperty("android")) { // Android libraries |
| 6 | + |
| 7 | + tasks.register('sourcesJar', Jar) { |
| 8 | + archiveClassifier.convention('sources') |
| 9 | + archiveClassifier.set('sources') |
| 10 | + from android.sourceSets.main.java.srcDirs |
| 11 | + } |
| 12 | + |
| 13 | + tasks.register('javadoc', Javadoc) { |
| 14 | + failOnError = true |
| 15 | + source = android.sourceSets.main.java.srcDirs |
| 16 | + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) |
| 17 | + } |
| 18 | +} else { // Java libraries |
| 19 | + tasks.register('sourcesJar', Jar) { |
| 20 | + dependsOn classes |
| 21 | + archiveClassifier.convention('sources') |
| 22 | + archiveClassifier.set('sources') |
| 23 | + from sourceSets.main.allSource |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +tasks.register('javadocJar', Jar) { |
| 28 | + if (project.hasProperty("android")) { |
| 29 | + dependsOn "javadoc" |
| 30 | + from javadoc.destinationDir |
| 31 | + } |
| 32 | + archiveClassifier.convention('javadoc') |
| 33 | + archiveClassifier.set('javadoc') |
| 34 | +} |
| 35 | + |
| 36 | +artifacts { |
| 37 | + archives javadocJar |
| 38 | + archives sourcesJar |
| 39 | +} |
| 40 | + |
| 41 | +group = project.getPublishProperty('groupId') |
| 42 | +version = project.getPublishProperty('versionName') |
| 43 | + |
| 44 | +ext["signing.keyId"] = '' |
| 45 | +ext["signing.password"] = '' |
| 46 | +ext["signing.secretKeyRingFile"] = '' |
| 47 | + |
| 48 | + |
| 49 | +File secretPropsFile = project.rootProject.file('local.properties') |
| 50 | +if (secretPropsFile.exists()) { |
| 51 | + Properties p = new Properties() |
| 52 | + p.load(new FileInputStream(secretPropsFile)) |
| 53 | + p.each { name, value -> |
| 54 | + ext[name] = value |
| 55 | + } |
| 56 | +} else { |
| 57 | + ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') |
| 58 | + ext["signing.password"] = System.getenv('SIGNING_PASSWORD') |
| 59 | + ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE') |
| 60 | +} |
| 61 | + |
| 62 | +afterEvaluate { |
| 63 | + publishing { |
| 64 | + publications { |
| 65 | + release(MavenPublication) { |
| 66 | + |
| 67 | + groupId = getPublishProperty('groupId') |
| 68 | + version = getPublishProperty('versionName') |
| 69 | + if (project.plugins.findPlugin("com.android.library")) { |
| 70 | + javadoc.classpath += files(android.libraryVariants.collect { variant -> |
| 71 | + variant.javaCompile.classpath.files |
| 72 | + }) |
| 73 | + from components.release |
| 74 | + } else { |
| 75 | + from components.java |
| 76 | + } |
| 77 | + |
| 78 | + artifact sourcesJar |
| 79 | + artifact javadocJar |
| 80 | + |
| 81 | + pom { |
| 82 | + name = getPublishProperty('libraryName') |
| 83 | + description = getPublishProperty('description') |
| 84 | + url = getPublishProperty('siteUrl') |
| 85 | + license { |
| 86 | + name = getPublishProperty('licenseName') |
| 87 | + url = getPublishProperty('licenseUrl') |
| 88 | + } |
| 89 | + developer { |
| 90 | + name = getPublishProperty('developerName') |
| 91 | + email = getPublishProperty('developerEmail') |
| 92 | + organization = getPublishProperty('developerName') |
| 93 | + organizationUrl = getPublishProperty('developerUrl') |
| 94 | + } |
| 95 | + scm { |
| 96 | + connection = getPublishProperty('scmUrl') |
| 97 | + developerConnection = getPublishProperty('scmUrl') |
| 98 | + url = getPublishProperty('siteUrl') |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | +} |
| 105 | + |
| 106 | +signing { |
| 107 | + sign publishing.publications |
| 108 | +} |
0 commit comments