Skip to content

Instantly share code, notes, and snippets.

@ibrahimsn98
Last active May 4, 2022 07:11
Show Gist options
  • Select an option

  • Save ibrahimsn98/3524fab9a4cea060b1824d84a79cee8e to your computer and use it in GitHub Desktop.

Select an option

Save ibrahimsn98/3524fab9a4cea060b1824d84a79cee8e to your computer and use it in GitHub Desktop.
apply plugin: 'maven-publish'
static def isReleaseBuild() {
return !Config.versionName.contains("SNAPSHOT")
}
def getOutputDir() {
if (isReleaseBuild()) {
return "${project.buildDir}/releases"
} else {
return "${project.buildDir}/snapshots"
}
}
def getArtifactFilePath() {
if (isReleaseBuild()) {
return "$buildDir/outputs/aar/${Config.artifactId}-release.aar"
} else {
return "$buildDir/outputs/aar/${Config.artifactId}-debug.aar"
}
}
def getPublicationName() {
if (isReleaseBuild()) {
return "release"
} else {
return "debug"
}
}
publishing {
publications {
"${getPublicationName()}" (MavenPublication) {
groupId Config.groupId // com.company.project
artifactId Config.artifactId // my-component-library
version Config.versionName // 1.0.0-SNAPSHOT
artifact getArtifactFilePath()
// To include project dependencies
pom.withXml {
def dependencies = asNode().appendNode('dependencies')
configurations.getByName("${getPublicationName()}CompileClasspath").getResolvedConfiguration().getFirstLevelModuleDependencies().each {
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', it.moduleGroup)
dependency.appendNode('artifactId', it.moduleName)
dependency.appendNode('version', it.moduleVersion)
}
}
}
}
repositories {
maven {
url "https://gitlab.com/api/v4/projects/projectId/packages/maven"
credentials(HttpHeaderCredentials) {
name = "Private-Token"
value = Config.gitLabAccessToken
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
@desgraci
Copy link

desgraci commented May 4, 2022

  • What went wrong:
    Execution failed for task ':generatePomFileForChatPublication'.

Could not apply withXml() to generated POM
Configuration with name 'testmoduleCompileClasspath' not found.

Adding this at the root, where is this supposed to be run?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment