wupdigital / android-maven-publish

Modification of the standard Maven Publish plugin to be compatible with android-library projects (aar).
Apache License 2.0
326 stars 39 forks source link

Publishing is not able to resolve a dependency on a project with multiple publications that have different coordinates. #25

Closed kkooff114 closed 6 years ago

kkooff114 commented 6 years ago

I have 2 lib modules : library , library2

build.gradle in library:

apply plugin: 'com.android.library'
apply plugin: 'digital.wup.android-maven-publish'

android {
    compileSdkVersion 26
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    flavorDimensions "runner"
    productFlavors {
        sit {
            dimension "runner"
        }
        dev {
            dimension "runner"
        }
        uat {
            dimension "runner"
        }
        prd {
            dimension "runner"
        }
    }

}

dependencies {
   ...
  implementation project(':android-library2')
}

apply from: '../publish.gradle'

build.gradle in library2:

apply plugin: 'com.android.library'
apply plugin: 'digital.wup.android-maven-publish'

android {
    compileSdkVersion 26
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    flavorDimensions "runner"
    productFlavors {
        sit {
            dimension "runner"
        }
        dev {
            dimension "runner"
        }
        uat {
            dimension "runner"
        }
        prd {
            dimension "runner"
        }
    }

}

dependencies {
   ...
}

apply from: '../publish.gradle'

publish.gradle:

publishing.publications() {
    android.libraryVariants.all { variant ->
        "maven$project.archivesBaseName${variant.name.capitalize()}Aar"(MavenPublication) {
            from components.findByName("android${variant.name.capitalize()}")
            groupId 'com.android.saleshelp'
            artifactId project.archivesBaseName + "-${variant.name.capitalize()}"
            version android.defaultConfig.versionName
        }
    }
}

publishing.repositories {
    mavenLocal()
}

when I run task publish in library, I got the following error:

* What went wrong:
Could not determine the dependencies of task ':android-library2:publishMavenandroid-library2SitReleaseAarPublicationToMavenLocalRepository'.
> Publishing is not able to resolve a dependency on a project with multiple publications that have different coordinates.
  Found the following publications in project ':android-library':
    - Maven publication 'mavenandroid-libraryPrdDebugAar' with coordinates com.cestbon.android.saleshelp:android-library-PrdDebug:1.0
    - Maven publication 'mavenandroid-libraryPrdReleaseAar' with coordinates com.cestbon.android.saleshelp:android-library-PrdRelease:1.0
    - Maven publication 'mavenandroid-libraryDevDebugAar' with coordinates com.cestbon.android.saleshelp:android-library-DevDebug:1.0
    - Maven publication 'mavenandroid-libraryDevReleaseAar' with coordinates com.cestbon.android.saleshelp:android-library-DevRelease:1.0
    - Maven publication 'mavenandroid-libraryUatDebugAar' with coordinates com.cestbon.android.saleshelp:android-library-UatDebug:1.0
    - Maven publication 'mavenandroid-libraryUatReleaseAar' with coordinates com.cestbon.android.saleshelp:android-library-UatRelease:1.0
    - Maven publication 'mavenandroid-librarySitDebugAar' with coordinates com.cestbon.android.saleshelp:android-library-SitDebug:1.0
    - Maven publication 'mavenandroid-librarySitReleaseAar' with coordinates com.cestbon.android.saleshelp:android-library-SitRelease:1.0

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

If I removed apply from: '../publish.gradle' in build.gradle of library2, task :library:publish can be run successfully. But because of I want to publish library2 independently, so library2 must apply from: '../publish.gradle'

How can I do for this error? Thanks.

warnyul commented 6 years ago

I answered your question on stackoverflow, because I think this is not an android-maven-publish plugin bug, this is a limitation of the original maven-publish plugin.