3

I have a library I'm trying to publish that has a dependency on another module in the same project with multiple publications as well. If I configure the gradle build files like this I run into an error.

build.gradle(Module:transaction-manager)

dependencies {
    api project(':library')
}



afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release
                groupId "com.example.sdk"
                artifactId "transaction-manager"
                version "1.0.0"
            }
            debug(MavenPublication) {
                from components.debug
                groupId "com.example.sdk"
                artifactId "transaction-manager-debug"
                version "1.0.0"
            }
        }
    }
}

build.gradle(Module:library)

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release
                groupId "com.example.sdk"
                artifactId "core"
                version "1.0.0"
            }
            debug(MavenPublication) {
                from components.debug
                groupId "com.example.sdk"
                artifactId "core-debug"
                version "1.0.0"
            }
        }
    }
}

Error

> Publishing is not able to resolve a dependency on a project with multiple publications that have different coordinates.
  Found the following publications in project ':library':
    - Maven publication 'release' with coordinates com.example.sdk:core:1.0.0
    - Maven publication 'debug' with coordinates com.example.sdk:core-debug:1.0.0

if I configure the gradle build like this I'm able to build with no issue.

build.gradle(Module:transaction-manager)

dependencies {
    debugApi 'com.example.sdk:core-debug:1.+'
    releaseApi 'com.example.sdk:core:1.+'
}

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release
                groupId "com.example.sdk"
                artifactId "transaction-manager"
                version "1.0.0"
            }
            debug(MavenPublication) {
                from components.debug
                groupId "com.example.sdk"
                artifactId "transaction-manager-debug"
                version "1.0.0"
            }
        }
    }
}

The only problem is that I have to build the core library first before I can build the transaction manager. I was wondering if there was a way for me to keep the transaction module pointing to the library with api project(':library') and specify which publication I want to use?

JC Castano
  • 135
  • 1
  • 6

0 Answers0