Revert file naming convention of .aar files to support fuzzy matching in build.gradle (#112149)

This commit is contained in:
林军华
2022-10-04 11:37:22 +08:00
committed by GitHub
parent 35afe1bdac
commit 8e30cc9c56
6 changed files with 41 additions and 252 deletions

View File

@@ -26,8 +26,10 @@ void configureProject(Project project, String outputDir) {
project.version = project.property("buildNumber")
}
project.android.libraryVariants.all { variant ->
addAarTask(project, variant)
project.components.forEach { component ->
if (component.name != "all") {
addAarTask(project, component)
}
}
project.publishing {
@@ -38,43 +40,6 @@ void configureProject(Project project, String outputDir) {
}
}
// Some extra work to have alternative publications with the same format as the old maven plugin.
// Instead of using classifiers for the variants, the old maven plugin appended `_{variant}` to the artifactId
// First, create a default MavenPublication for each variant (except "all" since that is used to publish artifacts in the new way)
project.components.forEach { component ->
if (component.name != "all") {
project.publishing.publications.create(component.name, MavenPublication) {
from component
}
}
}
// then, rename the artifactId to include the variant and make sure to remove any classifier
// data tha gradle has set, as well as adding a <relocation> tag pointing to the new coordinates
project.publishing.publications.forEach { pub ->
def relocationArtifactId = pub.artifactId
pub.artifactId = "${relocationArtifactId}_${pub.name}"
pub.alias = true
pub.pom.distributionManagement {
relocation {
// New artifact coordinates
groupId = "${pub.groupId}"
artifactId = "${relocationArtifactId}"
version = "${pub.version}"
message = "Use classifiers rather than _variant for new publish plugin"
}
}
}
// also publish the artifacts in the new way, using one set of coordinates with classifiers
project.publishing.publications.create("all", MavenPublication) {
from project.components.all
alias false
}
if (!project.property("is-plugin").toBoolean()) {
return
}
@@ -114,14 +79,23 @@ String getFlutterRoot(Project project) {
return project.property("flutter-root")
}
void addAarTask(Project project, variant) {
String variantName = variant.name.capitalize()
void addAarTask(Project project, component) {
String variantName = component.name.capitalize()
String taskName = "assembleAar$variantName"
project.tasks.create(name: taskName) {
// This check is required to be able to configure the archives before `publish` runs.
if (!project.gradle.startParameter.taskNames.contains(taskName)) {
return
}
// Create a default MavenPublication for the variant (except "all" since that is used to publish artifacts in the new way)
project.publishing.publications.create(component.name, MavenPublication) { pub ->
groupId = "${pub.groupId}"
artifactId = "${pub.artifactId}_${pub.name}"
version = "${pub.version}"
from component
}
// Generate the Maven artifacts.
finalizedBy "publish"
}

View File

@@ -726,7 +726,7 @@ void printHowToConsumeAar({
for (final String buildMode in buildModes) {
logger.printStatus("""
${buildMode}Implementation '$androidPackage:flutter:$buildNumber:$buildMode'""");
${buildMode}Implementation '$androidPackage:flutter_$buildMode:$buildNumber'""");
}
logger.printStatus('''

View File

@@ -540,9 +540,9 @@ flutter:
' 3. Make the host app depend on the Flutter module:\n'
'\n'
' dependencies {\n'
" releaseImplementation 'com.mycompany:flutter:2.2:release'\n"
" debugImplementation 'com.mycompany:flutter:2.2:debug'\n"
" profileImplementation 'com.mycompany:flutter:2.2:profile'\n"
" releaseImplementation 'com.mycompany:flutter_release:2.2'\n"
" debugImplementation 'com.mycompany:flutter_debug:2.2'\n"
" profileImplementation 'com.mycompany:flutter_profile:2.2'\n"
' }\n'
'\n'
'\n'
@@ -591,7 +591,7 @@ flutter:
' 3. Make the host app depend on the Flutter module:\n'
'\n'
' dependencies {\n'
" releaseImplementation 'com.mycompany:flutter:1.0:release'\n"
" releaseImplementation 'com.mycompany:flutter_release:1.0'\n"
' }\n'
'\n'
'To learn more, visit https://flutter.dev/go/build-aar\n'
@@ -629,7 +629,7 @@ flutter:
' 3. Make the host app depend on the Flutter module:\n'
'\n'
' dependencies {\n'
" debugImplementation 'com.mycompany:flutter:1.0:debug'\n"
" debugImplementation 'com.mycompany:flutter_debug:1.0'\n"
' }\n'
'\n'
'To learn more, visit https://flutter.dev/go/build-aar\n'
@@ -668,7 +668,7 @@ flutter:
' 3. Make the host app depend on the Flutter module:\n'
'\n'
' dependencies {\n'
" profileImplementation 'com.mycompany:flutter:1.0:profile'\n"
" profileImplementation 'com.mycompany:flutter_profile:1.0'\n"
' }\n'
'\n'
'\n'