Skip to content

Commit

Permalink
chore: Move to using the Maven Publish DSL (#2815)
Browse files Browse the repository at this point in the history
Co-authored-by: Tyler Roach <[email protected]>
  • Loading branch information
mattcreaser and tylerjroach authored May 15, 2024
1 parent 7636abe commit bded3bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ fun Project.configureAndroid() {
)
)
}

publishing {
singleVariant("release") {
withSourcesJar()
}
}
}

dependencies {
Expand Down
36 changes: 13 additions & 23 deletions configuration/publishing.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,14 @@ def getRepositoryPassword() {
}

afterEvaluate { project ->
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.source
}


publishing {
publications {
library(MavenPublication) {
groupId POM_GROUP
artifactId POM_ARTIFACT_ID
version VERSION_NAME

artifact("${buildDir}/outputs/aar/${artifactId}-release.aar")
if (project.getPlugins().hasPlugin('com.android.application') ||
project.getPlugins().hasPlugin('com.android.library')) {
artifact(androidSourcesJar)
} else {
artifact(sourcesJar)
}
from(components.named("release").get())

pom {
name = POM_NAME
Expand Down Expand Up @@ -92,16 +80,12 @@ afterEvaluate { project ->
}

withXml {
def dependenciesNode = asNode().appendNode('dependencies')
// Note that this only handles implementation
// dependencies. In the future, may need to add api,
// etc.
configurations.implementation.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
// Remove the scope information for all dependencies. This puts
// everything at "compile" scope, which matches the way Amplify V2 has been
// published historically. For v3 we should remove this and include the
// scope information for our dependencies.
def dependencies = asNode().get('dependencies').first()
dependencies.each { it.remove(it.get('scope')) }
}
}
}
Expand All @@ -128,4 +112,10 @@ afterEvaluate { project ->
}
sign publishing.publications.library
}

// Turn off Gradle metadata. This is to maintain compatibility with the way Amplify V2 has
// been published historically. For v3 we should remove this and publish the gradle metadata.
tasks.withType(GenerateModuleMetadata).configureEach {
enabled = false
}
}

0 comments on commit bded3bc

Please sign in to comment.