Hey all. What is the actual way to set different a...
# multiplatform
s
Hey all. What is the actual way to set different artifact IDs when publishing a KMP project?
Copy code
publishing {
    publications.withType<MavenPublication> {
        artifactId = "custom-name"
        configureMavenPom(project)
        signing { if (isRelease) sign(this@withType) }
    }
}
This will create a publication with the right name for the artifact but appears to be causing a bug when actually trying to use it. Someone is having the same issue here: https://stackoverflow.com/questions/70489135/unable-to-use-published-kmp-library-due-[…]o-error-detecting-cycle-in-external-va/70490150?noredirect=1 So my IDE can detect the dependency that I published (above), but Gradle cannot seem to resolve it. The actual error message:
Copy code
Detecting cycle in external variants for :
my.dependency:dependency:version: //<---- the one i published (above)
  - my.other.project:other:version
Dependency resolution has ignored the cycle to produce a result. It is recommended to resolve the cycle by upgrading one or more dependencies.
h
Why do want to change the artifactID at all? How about just rename the module name?
s
Because I'd like to be able to change the artifact ID to whatever I want without it causing some dependency resolution bug. Either I'm not doing it correctly or there is a bug with the KMP plugin, which needs to be reported.
h
I agree this sounds like a bug. As a workaround you can do this via
rootProject.name = 'myproject'
too for a single module project.
o
Is this bug new or something? I have the same problem too. Did you resolve it @Shan?
the workaround didn't work for me
s
I did not resolve it. I ended up just renaming my project modules to get the artifacts to be correct 😕 Have an issue to go back and fix it once this is resolved.
o
I'm doing the same right now. That's sad
Can you show me your artifactory block if it's okay with you Shan? Also what does
configureMavenPom
do?
s
Copy code
fun MavenPublication.configureMavenPom(project: Project) {
    version = project.version.toString()

    pom {
        name.set(project.name)
        description.set(Info.pomDescription)
        url.set(Info.projectUrl)

        licenses {
            license {
                name.set(Info.pomLicense)
                url.set(Info.pomLicenseUrl)
            }
        }
        developers {
            developer {
                email.set(Info.projectDevEmail)
            }
        }
        organization {
            name.set(Info.pomOrg)
        }
        scm {
            connection.set(Info.projectCloneUrl)
            url.set(Info.projectUrl)
        }
    }
}
I use this in multiple projects so just abstracted it out.
setMavenRepositories()
is a function which sets my repo to my Space repository w/ credentials for publishing, not using Artifactory, sorry!
Copy code
fun PublishingExtension.setMavenRepositories() {
    repositories {
        maven {
            url = URI("my repo url")

            credentials {
                username = System.getenv("space client user")
                password = System.getenv("space client pw")
            }
        }
    }
}
i imagine with artifactory the setup is something similar