Last active
May 4, 2022 07:11
-
-
Save ibrahimsn98/3524fab9a4cea060b1824d84a79cee8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} | |
} |
@mbilal51214 try like this;
apply plugin: 'maven-publish'
def mVersionName = "..."
def mGroupId = "..."
def mArtifactId = "..."
def mGitLabAccessToken = "..."
static def isReleaseBuild() {
return !mVersionName.contains("SNAPSHOT")
}
def getOutputDir() {
if (isReleaseBuild()) {
return "${project.buildDir}/releases"
} else {
return "${project.buildDir}/snapshots"
}
}
def getArtifactFilePath() {
if (isReleaseBuild()) {
return "$buildDir/outputs/aar/${artifactId}-release.aar"
} else {
return "$buildDir/outputs/aar/${artifactId}-debug.aar"
}
}
def getPublicationName() {
if (isReleaseBuild()) {
return "release"
} else {
return "debug"
}
}
publishing {
publications {
"${getPublicationName()}" (MavenPublication) {
groupId mGroupId // com.company.project
artifactId mArtifactId // my-component-library
version mVersionName // 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 = mGitLabAccessToken
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
@ibrahimsn98 url "https://gitlab.com/api/v4/projects/projectId/packages/maven" Which url will be used here?
apply from: "$rootDir/gradle-mvn-push.gradle"
where to put this line in build.gradle. I mean before android or inside android block {}
- 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
Cannot resolve symbol 'Config'