Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kishannareshpal/2c3e3ac25c23d23f363bcb2edf94e3f2 to your computer and use it in GitHub Desktop.
Save kishannareshpal/2c3e3ac25c23d23f363bcb2edf94e3f2 to your computer and use it in GitHub Desktop.

Revisions

  1. @gsavvid gsavvid revised this gist Jul 9, 2019. No changes.
  2. @gsavvid gsavvid revised this gist Jul 9, 2019. No changes.
  3. Georgios Savvidis revised this gist Jul 9, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions publishMavenBintray.gradle
    Original file line number Diff line number Diff line change
    @@ -98,9 +98,9 @@ project.afterEvaluate {
    publishing {
    publications {
    Production(MavenPublication) {
    groupId "YOUR GROUP ID" // If you publish to Bintray, make sure that this is the same as the "group" field at the top of this file.
    groupId "YOUR GROUP ID" // If you publish to Bintray, make sure that this is the same as the "group" field at the top of this file.
    artifactId "YOUR ARTIFACT ID"
    version = "YOUR ARTIFACT VERSION" // If you publish to Bintray, make sure that this is the same as the "version" field at the top of this file.
    version = "YOUR ARTIFACT VERSION" // If you publish to Bintray, make sure that this is the same as the "version" field at the top of this file.

    artifact bundleReleaseAar
    artifact androidJavadocsJar
  4. Georgios Savvidis renamed this gist Jul 9, 2019. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions publishMavenLocal.gradle → publishMavenBintray.gradle
    Original file line number Diff line number Diff line change
    @@ -30,8 +30,8 @@ apply plugin: 'com.jfrog.bintray'
    group = 'YOUR BINTRAY GROUP ID'
    version = 'YOUR BINTRAY ARTIFACT VERSION'

    // For more details on Bintray's configuration, see https://github.com/bintray/gradle-bintray-plugin.
    bintray {
    // For more details on Bintray's configuration, see https://github.com/bintray/gradle-bintray-plugin
    user = "YOUR BINTRAY USERNAME"
    key = "YOUR BINTRAY API KEY"
    publications = ['Production']
    @@ -54,9 +54,8 @@ bintray {
    }
    }

    // For more details on Dokka's configuration, see https://github.com/Kotlin/dokka.
    dokka {
    // For more details on Dokka's configuration, see https://github.com/Kotlin/dokka.

    // Minimal configuration.
    outputFormat = 'javadoc'
    outputDirectory = "$buildDir/javadoc"
  5. Georgios Savvidis revised this gist Jul 9, 2019. 1 changed file with 84 additions and 23 deletions.
    107 changes: 84 additions & 23 deletions publishMavenLocal.gradle
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,93 @@
    /**
    * Publish Local Helper
    * Publish Android Kotlin Library Helper
    *
    * @Author Robert Pösel
    * @Version 1.4
    * @Date 24.4.2019
    * This Gradle script is based on https://gist.github.com/Robyer/a6578e60127418b380ca133a1291f017.
    * The difference is that:
    * 1. It uses Dokka for generating Kotlin Javadoc.
    * 2. It uses Jfrog's plugin for publishing to Bintray. If you don't want to publish to Bintray, simply remove all the Bintray-related code.
    *
    * NOTE: You need to add Dokka and Bintray to your classpath for the two plugins to work.
    * Update the buildscript in your project's build.gradle with the following:
    *
    * buildscript {
    * dependencies {
    * classpath 'org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.18'
    * classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
    * }
    * }
    *
    * @See https://github.com/Kotlin/dokka
    * @See https://github.com/bintray/gradle-bintray-plugin
    *
    * @Author Georgios Savvidis
    * @Version 1.0
    * @Date 9.7.2019
    */

    apply plugin: 'maven-publish'
    apply plugin: 'org.jetbrains.dokka-android'
    apply plugin: 'com.jfrog.bintray'

    task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    android.libraryVariants.all { variant ->
    if (variant.name == 'release') {
    if (variant.hasProperty('javaCompileProvider')) {
    // Android 3.3.0+
    owner.classpath += variant.javaCompileProvider.get().classpath
    } else {
    owner.classpath += variant.javaCompile.classpath
    group = 'YOUR BINTRAY GROUP ID'
    version = 'YOUR BINTRAY ARTIFACT VERSION'

    bintray {
    // For more details on Bintray's configuration, see https://github.com/bintray/gradle-bintray-plugin
    user = "YOUR BINTRAY USERNAME"
    key = "YOUR BINTRAY API KEY"
    publications = ['Production']
    configurations = ['archives']

    pkg {
    repo = "YOUR BINTRAY REPO"
    userOrg = "YOUR BINTRAY ORG"
    name = "YOUR BINTRAY PACKAGE NAME"
    dryRun = false
    publish = true
    override = false
    publicDownloadNumbers = false
    version {
    gpg {
    sign = true
    passphrase = "YOUR BINTRAY GPG PASSPHRASE"
    }
    }
    }
    exclude '**/R.html', '**/R.*.html', '**/index.html'
    }

    task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
    dokka {
    // For more details on Dokka's configuration, see https://github.com/Kotlin/dokka.

    // Minimal configuration.
    outputFormat = 'javadoc'
    outputDirectory = "$buildDir/javadoc"

    // Use to include or exclude non public members.
    includeNonPublic = false

    // Do not output deprecated members. Applies globally, can be overridden by packageOptions.
    skipDeprecated = false

    // Emit warnings about not documented members. Applies globally, also can be overridden by packageOptions.
    reportUndocumented = true

    // Do not create index pages for empty packages
    skipEmptyPackages = true

    // Example of how to link to external documentation.
    // The following links to AndroidX.
    // Repeat for multiple links.
    externalDocumentationLink {
    // Root URL of the generated documentation to link with. The trailing slash is required!
    url = new URL("https://developer.android.com/reference/")

    // If package-list file located in non-standard location
    packageListUrl = new URL("https://developer.android.com/reference/androidx/package-list")
    }
    }

    task androidJavadocsJar(type: Jar, dependsOn: dokka) {
    classifier = 'javadoc'
    from androidJavadocs.destinationDir
    from dokka.outputDirectory
    }

    task androidSourcesJar(type: Jar) {
    @@ -37,10 +98,10 @@ task androidSourcesJar(type: Jar) {
    project.afterEvaluate {
    publishing {
    publications {
    maven(MavenPublication) {
    //groupId 'cz.example'
    //artifactId 'custom-artifact'
    //version = android.defaultConfig.versionName
    Production(MavenPublication) {
    groupId "YOUR GROUP ID" // If you publish to Bintray, make sure that this is the same as the "group" field at the top of this file.
    artifactId "YOUR ARTIFACT ID"
    version = "YOUR ARTIFACT VERSION" // If you publish to Bintray, make sure that this is the same as the "version" field at the top of this file.

    artifact bundleReleaseAar
    artifact androidJavadocsJar
    @@ -85,4 +146,4 @@ project.afterEvaluate {
    }
    }
    }
    }
    }
  6. @Robyer Robyer revised this gist Jun 28, 2019. 1 changed file with 55 additions and 39 deletions.
    94 changes: 55 additions & 39 deletions publishMavenLocal.gradle
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,24 @@
    /**
    * Publish Local Helper
    *
    * @Author Robert Pösel
    * @Version 1.4
    * @Date 24.4.2019
    */

    apply plugin: 'maven-publish'

    task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    android.libraryVariants.all { variant ->
    if (variant.name == 'release') {
    owner.classpath += variant.javaCompile.classpath
    if (variant.hasProperty('javaCompileProvider')) {
    // Android 3.3.0+
    owner.classpath += variant.javaCompileProvider.get().classpath
    } else {
    owner.classpath += variant.javaCompile.classpath
    }
    }
    }
    exclude '**/R.html', '**/R.*.html', '**/index.html'
    @@ -21,52 +34,55 @@ task androidSourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    }

    publishing {
    publications {
    maven(MavenPublication) {
    //groupId 'cz.example'
    //artifactId 'custom-artifact'
    //version = android.defaultConfig.versionName
    project.afterEvaluate {
    publishing {
    publications {
    maven(MavenPublication) {
    //groupId 'cz.example'
    //artifactId 'custom-artifact'
    //version = android.defaultConfig.versionName

    artifact bundleReleaseAar
    artifact androidJavadocsJar
    artifact androidSourcesJar
    artifact bundleReleaseAar
    artifact androidJavadocsJar
    artifact androidSourcesJar

    pom.withXml {
    final dependenciesNode = asNode().appendNode('dependencies')
    pom.withXml {
    final dependenciesNode = asNode().appendNode('dependencies')

    ext.addDependency = { Dependency dep, String scope ->
    if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
    return // ignore invalid dependencies
    ext.addDependency = { dep, String scope ->
    if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
    return // ignore invalid dependencies

    final dependencyNode = dependenciesNode.appendNode('dependency')
    dependencyNode.appendNode('groupId', dep.group)
    dependencyNode.appendNode('artifactId', dep.name)
    dependencyNode.appendNode('version', dep.version)
    dependencyNode.appendNode('scope', scope)
    final dependencyNode = dependenciesNode.appendNode('dependency')
    dependencyNode.appendNode('groupId', dep.group)
    dependencyNode.appendNode('artifactId', dep.name)
    dependencyNode.appendNode('version', dep.version)
    dependencyNode.appendNode('scope', scope)

    if (!dep.transitive) {
    // If this dependency is transitive, we should force exclude all its dependencies them from the POM
    final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
    exclusionNode.appendNode('groupId', '*')
    exclusionNode.appendNode('artifactId', '*')
    } else if (!dep.properties.excludeRules.empty) {
    // Otherwise add specified exclude rules
    final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
    dep.properties.excludeRules.each { ExcludeRule rule ->
    exclusionNode.appendNode('groupId', rule.group ?: '*')
    exclusionNode.appendNode('artifactId', rule.module ?: '*')
    if (!dep.transitive) {
    // If this dependency is not transitive, we should force exclude all its dependencies from the POM
    final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
    exclusionNode.appendNode('groupId', '*')
    exclusionNode.appendNode('artifactId', '*')
    } else if (!dep.properties.excludeRules.empty) {
    // Otherwise add specified exclude rules
    final exclusionsNode = dependencyNode.appendNode('exclusions')
    dep.properties.excludeRules.each { rule ->
    final exclusionNode = exclusionsNode.appendNode('exclusion')
    exclusionNode.appendNode('groupId', rule.group ?: '*')
    exclusionNode.appendNode('artifactId', rule.module ?: '*')
    }
    }
    }
    }

    // List all "compile" dependencies (for old Gradle)
    configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") }
    // List all "api" dependencies (for new Gradle) as "compile" dependencies
    configurations.api.getDependencies().each { dep -> addDependency(dep, "compile") }
    // List all "implementation" dependencies (for new Gradle) as "runtime" dependencies
    configurations.implementation.getDependencies().each { dep -> addDependency(dep, "runtime") }
    // List all "compile" dependencies (for old Gradle)
    configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") }
    // List all "api" dependencies (for new Gradle) as "compile" dependencies
    configurations.api.getDependencies().each { dep -> addDependency(dep, "compile") }
    // List all "implementation" dependencies (for new Gradle) as "runtime" dependencies
    configurations.implementation.getDependencies().each { dep -> addDependency(dep, "runtime") }
    }
    }
    }
    }
    }
    }
  7. @Robyer Robyer revised this gist Nov 23, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions publishMavenLocal.gradle
    Original file line number Diff line number Diff line change
    @@ -61,11 +61,11 @@ publishing {
    }

    // List all "compile" dependencies (for old Gradle)
    configurations.compile.getAllDependencies().each { dep -> addDependency(dep, "compile") }
    configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") }
    // List all "api" dependencies (for new Gradle) as "compile" dependencies
    configurations.api.getAllDependencies().each { dep -> addDependency(dep, "compile") }
    configurations.api.getDependencies().each { dep -> addDependency(dep, "compile") }
    // List all "implementation" dependencies (for new Gradle) as "runtime" dependencies
    configurations.implementation.getAllDependencies().each { dep -> addDependency(dep, "runtime") }
    configurations.implementation.getDependencies().each { dep -> addDependency(dep, "runtime") }
    }
    }
    }
  8. @Robyer Robyer revised this gist Nov 23, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion publishMavenLocal.gradle
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ publishing {
    //artifactId 'custom-artifact'
    //version = android.defaultConfig.versionName

    artifact bundleRelease
    artifact bundleReleaseAar
    artifact androidJavadocsJar
    artifact androidSourcesJar

  9. @Robyer Robyer revised this gist Mar 27, 2018. 1 changed file with 54 additions and 50 deletions.
    104 changes: 54 additions & 50 deletions publishMavenLocal.gradle
    Original file line number Diff line number Diff line change
    @@ -1,68 +1,72 @@
    apply plugin: 'maven-publish'

    task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    android.libraryVariants.all { variant ->
    if (variant.name == 'release') {
    owner.classpath += variant.javaCompile.classpath
    }
    }
    exclude '**/R.html', '**/R.*.html', '**/index.html'
    }

    task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
    classifier = 'javadoc'
    from androidJavadocs.destinationDir
    classifier = 'javadoc'
    from androidJavadocs.destinationDir
    }

    task androidSourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
    }

    publishing {
    publications {
    maven(MavenPublication) {
    groupId 'com.example'
    artifactId 'custom-artifact'
    version '1.0'
    // Or use same version as in android branch
    // version = android.defaultConfig.versionName
    publications {
    maven(MavenPublication) {
    //groupId 'cz.example'
    //artifactId 'custom-artifact'
    //version = android.defaultConfig.versionName

    artifact bundleRelease
    artifact androidJavadocsJar
    artifact androidSourcesJar
    artifact bundleRelease
    artifact androidJavadocsJar
    artifact androidSourcesJar

    pom.withXml {
    def dependenciesNode = asNode().appendNode('dependencies')
    pom.withXml {
    final dependenciesNode = asNode().appendNode('dependencies')

    def dependencies = []
    // List all "compile" dependencies (for old Gradle)
    dependencies.addAll(configurations.compile.getAllDependencies())
    // List all "api" dependencies (for new Gradle)
    dependencies.addAll(configurations.api.getAllDependencies())
    ext.addDependency = { Dependency dep, String scope ->
    if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
    return // ignore invalid dependencies

    // Write dependencies to POM
    dependencies.each { Dependency dep ->
    if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
    return // ignore invalid dependencies
    final dependencyNode = dependenciesNode.appendNode('dependency')
    dependencyNode.appendNode('groupId', dep.group)
    dependencyNode.appendNode('artifactId', dep.name)
    dependencyNode.appendNode('version', dep.version)
    dependencyNode.appendNode('scope', scope)

    def dependencyNode = dependenciesNode.appendNode('dependency')
    dependencyNode.appendNode('groupId', dep.group)
    dependencyNode.appendNode('artifactId', dep.name)
    dependencyNode.appendNode('version', dep.version)
    if (!dep.transitive) {
    // If this dependency is transitive, we should force exclude all its dependencies them from the POM
    final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
    exclusionNode.appendNode('groupId', '*')
    exclusionNode.appendNode('artifactId', '*')
    } else if (!dep.properties.excludeRules.empty) {
    // Otherwise add specified exclude rules
    final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
    dep.properties.excludeRules.each { ExcludeRule rule ->
    exclusionNode.appendNode('groupId', rule.group ?: '*')
    exclusionNode.appendNode('artifactId', rule.module ?: '*')
    }
    }
    }

    if (!dep.transitive) {
    // If this dependency is transitive, we should force exclude all its dependencies them from the POM
    def exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
    exclusionNode.appendNode('groupId', '*')
    exclusionNode.appendNode('artifactId', '*')
    } else if (!dep.properties.excludeRules.empty) {
    // Otherwise add specified exclude rules
    def exclusionsNode = dependencyNode.appendNode('exclusions')
    dep.properties.excludeRules.each { ExcludeRule rule ->
    def exclusionNode = exclusionsNode.appendNode('exclusion')
    exclusionNode.appendNode('groupId', rule.group ?: '*')
    exclusionNode.appendNode('artifactId', rule.module ?: '*')
    }
    }
    }
    }
    }
    }
    }
    // List all "compile" dependencies (for old Gradle)
    configurations.compile.getAllDependencies().each { dep -> addDependency(dep, "compile") }
    // List all "api" dependencies (for new Gradle) as "compile" dependencies
    configurations.api.getAllDependencies().each { dep -> addDependency(dep, "compile") }
    // List all "implementation" dependencies (for new Gradle) as "runtime" dependencies
    configurations.implementation.getAllDependencies().each { dep -> addDependency(dep, "runtime") }
    }
    }
    }
    }
  10. @Robyer Robyer revised this gist Mar 27, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion publishMavenLocal.gradle
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ publishing {
    pom.withXml {
    def dependenciesNode = asNode().appendNode('dependencies')

    dependencies = []
    def dependencies = []
    // List all "compile" dependencies (for old Gradle)
    dependencies.addAll(configurations.compile.getAllDependencies())
    // List all "api" dependencies (for new Gradle)
  11. @Robyer Robyer revised this gist Mar 27, 2018. 1 changed file with 14 additions and 8 deletions.
    22 changes: 14 additions & 8 deletions publishMavenLocal.gradle
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,18 @@
    apply plugin: 'maven-publish'

    task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    }

    task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
    classifier = 'javadoc'
    from androidJavadocs.destinationDir
    classifier = 'javadoc'
    from androidJavadocs.destinationDir
    }

    task androidSourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
    }

    publishing {
    @@ -31,8 +31,14 @@ publishing {
    pom.withXml {
    def dependenciesNode = asNode().appendNode('dependencies')

    // List all compile dependencies and write to POM
    configurations.compile.getAllDependencies().each { Dependency dep ->
    dependencies = []
    // List all "compile" dependencies (for old Gradle)
    dependencies.addAll(configurations.compile.getAllDependencies())
    // List all "api" dependencies (for new Gradle)
    dependencies.addAll(configurations.api.getAllDependencies())

    // Write dependencies to POM
    dependencies.each { Dependency dep ->
    if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
    return // ignore invalid dependencies

  12. @Robyer Robyer revised this gist Mar 2, 2017. 1 changed file with 43 additions and 42 deletions.
    85 changes: 43 additions & 42 deletions publishMavenLocal.gradle
    Original file line number Diff line number Diff line change
    @@ -16,46 +16,47 @@ task androidSourcesJar(type: Jar) {
    }

    publishing {
    publications {
    maven(MavenPublication) {
    groupId 'com.example'
    artifactId 'custom-artifact'
    version '1.0'
    // Or use same version as in android branch
    // version = android.defaultConfig.versionName

    artifact bundleRelease
    artifact androidJavadocsJar
    artifact androidSourcesJar

    pom.withXml {
    def dependenciesNode = asNode().appendNode('dependencies')

    // List all compile dependencies and write to POM
    configurations.compile.getAllDependencies().each { Dependency dep ->
    if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
    return // ignore invalid dependencies

    def dependencyNode = dependenciesNode.appendNode('dependency')
    dependencyNode.appendNode('groupId', dep.group)
    dependencyNode.appendNode('artifactId', dep.name)
    dependencyNode.appendNode('version', dep.version)

    if (!dep.transitive) {
    // If this dependency is transitive, we should force exclude all its dependencies them from the POM
    def exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
    exclusionNode.appendNode('groupId', '*')
    exclusionNode.appendNode('artifactId', '*')
    } else if (!dep.properties.excludeRules.empty) {
    // Otherwise add specified exclude rules
    def exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
    dep.properties.excludeRules.each { ExcludeRule rule ->
    exclusionNode.appendNode('groupId', rule.group ?: '*')
    exclusionNode.appendNode('artifactId', rule.module ?: '*')
    }
    }
    }
    }
    }
    }
    publications {
    maven(MavenPublication) {
    groupId 'com.example'
    artifactId 'custom-artifact'
    version '1.0'
    // Or use same version as in android branch
    // version = android.defaultConfig.versionName

    artifact bundleRelease
    artifact androidJavadocsJar
    artifact androidSourcesJar

    pom.withXml {
    def dependenciesNode = asNode().appendNode('dependencies')

    // List all compile dependencies and write to POM
    configurations.compile.getAllDependencies().each { Dependency dep ->
    if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
    return // ignore invalid dependencies

    def dependencyNode = dependenciesNode.appendNode('dependency')
    dependencyNode.appendNode('groupId', dep.group)
    dependencyNode.appendNode('artifactId', dep.name)
    dependencyNode.appendNode('version', dep.version)

    if (!dep.transitive) {
    // If this dependency is transitive, we should force exclude all its dependencies them from the POM
    def exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
    exclusionNode.appendNode('groupId', '*')
    exclusionNode.appendNode('artifactId', '*')
    } else if (!dep.properties.excludeRules.empty) {
    // Otherwise add specified exclude rules
    def exclusionsNode = dependencyNode.appendNode('exclusions')
    dep.properties.excludeRules.each { ExcludeRule rule ->
    def exclusionNode = exclusionsNode.appendNode('exclusion')
    exclusionNode.appendNode('groupId', rule.group ?: '*')
    exclusionNode.appendNode('artifactId', rule.module ?: '*')
    }
    }
    }
    }
    }
    }
    }
  13. @Robyer Robyer revised this gist Feb 10, 2017. 1 changed file with 16 additions and 7 deletions.
    23 changes: 16 additions & 7 deletions publishMavenLocal.gradle
    Original file line number Diff line number Diff line change
    @@ -32,18 +32,27 @@ publishing {
    def dependenciesNode = asNode().appendNode('dependencies')

    // List all compile dependencies and write to POM
    configurations.compile.getResolvedConfiguration().firstLevelModuleDependencies.each { ResolvedDependency dep ->
    configurations.compile.getAllDependencies().each { Dependency dep ->
    if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
    return // ignore invalid dependencies

    def dependencyNode = dependenciesNode.appendNode('dependency')
    dependencyNode.appendNode('groupId', dep.moduleGroup)
    dependencyNode.appendNode('artifactId', dep.moduleName)
    dependencyNode.appendNode('version', dep.moduleVersion)
    dependencyNode.appendNode('groupId', dep.group)
    dependencyNode.appendNode('artifactId', dep.name)
    dependencyNode.appendNode('version', dep.version)

    // If this dependency has no transitive dependencies (perhaps it specified "@aar" or "transitive: false"),
    // we should force exclude them from the POM
    if (dep.children.empty) {
    if (!dep.transitive) {
    // If this dependency is transitive, we should force exclude all its dependencies them from the POM
    def exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
    exclusionNode.appendNode('groupId', '*')
    exclusionNode.appendNode('artifactId', '*')
    } else if (!dep.properties.excludeRules.empty) {
    // Otherwise add specified exclude rules
    def exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
    dep.properties.excludeRules.each { ExcludeRule rule ->
    exclusionNode.appendNode('groupId', rule.group ?: '*')
    exclusionNode.appendNode('artifactId', rule.module ?: '*')
    }
    }
    }
    }
  14. @Robyer Robyer revised this gist Feb 10, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion publishMavenLocal.gradle
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ publishing {
    maven(MavenPublication) {
    groupId 'com.example'
    artifactId 'custom-artifact'
    version '1.0
    version '1.0'
    // Or use same version as in android branch
    // version = android.defaultConfig.versionName

  15. @Robyer Robyer created this gist Feb 10, 2017.
    52 changes: 52 additions & 0 deletions publishMavenLocal.gradle
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    apply plugin: 'maven-publish'

    task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    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.srcDirs
    }

    publishing {
    publications {
    maven(MavenPublication) {
    groupId 'com.example'
    artifactId 'custom-artifact'
    version '1.0
    // Or use same version as in android branch
    // version = android.defaultConfig.versionName
    artifact bundleRelease
    artifact androidJavadocsJar
    artifact androidSourcesJar
    pom.withXml {
    def dependenciesNode = asNode().appendNode('dependencies')
    // List all compile dependencies and write to POM
    configurations.compile.getResolvedConfiguration().firstLevelModuleDependencies.each { ResolvedDependency dep ->
    def dependencyNode = dependenciesNode.appendNode('dependency')
    dependencyNode.appendNode('groupId', dep.moduleGroup)
    dependencyNode.appendNode('artifactId', dep.moduleName)
    dependencyNode.appendNode('version', dep.moduleVersion)
    // If this dependency has no transitive dependencies (perhaps it specified "@aar" or "transitive: false"),
    // we should force exclude them from the POM
    if (dep.children.empty) {
    def exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
    exclusionNode.appendNode('groupId', '*')
    exclusionNode.appendNode('artifactId', '*')
    }
    }
    }
    }
    }
    }