"Fossies" - the Fresh Open Source Software Archive

Member "flutter-3.7.1/packages/flutter_tools/gradle/aar_init_script.gradle" (1 Feb 2023, 5769 Bytes) of package /linux/misc/flutter-3.7.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Java source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "aar_init_script.gradle": 3.3.10_vs_3.7.0.

    1 // This script is used to initialize the build in a module or plugin project.
    2 // During this phase, the script applies the Maven plugin and configures the
    3 // destination of the local repository.
    4 // The local repository will contain the AAR and POM files.
    5 
    6 import java.nio.file.Paths
    7 import org.gradle.api.Project
    8 import org.gradle.api.artifacts.Configuration
    9 import org.gradle.api.publish.maven.MavenPublication
   10 
   11 void configureProject(Project project, String outputDir) {
   12     if (!project.hasProperty("android")) {
   13         throw new GradleException("Android property not found.")
   14     }
   15     if (!project.android.hasProperty("libraryVariants")) {
   16         throw new GradleException("Can't generate AAR on a non Android library project.");
   17     }
   18 
   19     // Snapshot versions include the timestamp in the artifact name.
   20     // Therefore, remove the snapshot part, so new runs of `flutter build aar` overrides existing artifacts.
   21     // This version isn't relevant in Flutter since the pub version is used
   22     // to resolve dependencies.
   23     project.version = project.version.replace("-SNAPSHOT", "")
   24 
   25     if (project.hasProperty("buildNumber")) {
   26         project.version = project.property("buildNumber")
   27     }
   28 
   29     project.components.forEach { component ->
   30         if (component.name != "all") {
   31             addAarTask(project, component)
   32         }
   33     }
   34 
   35     project.publishing {
   36         repositories {
   37             maven {
   38                 url = uri("file://${outputDir}/outputs/repo")
   39             }
   40         }
   41     }
   42 
   43     if (!project.property("is-plugin").toBoolean()) {
   44         return
   45     }
   46 
   47     String storageUrl = System.getenv('FLUTTER_STORAGE_BASE_URL') ?: "https://storage.googleapis.com"
   48     // This is a Flutter plugin project. Plugin projects don't apply the Flutter Gradle plugin,
   49     // as a result, add the dependency on the embedding.
   50     project.repositories {
   51         maven {
   52             url "$storageUrl/download.flutter.io"
   53         }
   54     }
   55     String engineVersion = Paths.get(getFlutterRoot(project), "bin", "internal", "engine.version")
   56         .toFile().text.trim()
   57     project.dependencies {
   58         // Add the embedding dependency.
   59         compileOnly ("io.flutter:flutter_embedding_release:1.0.0-$engineVersion") {
   60             // We only need to expose io.flutter.plugin.*
   61             // No need for the embedding transitive dependencies.
   62             transitive = false
   63         }
   64     }
   65 }
   66 
   67 void configurePlugin(Project project, String outputDir) {
   68     if (!project.hasProperty("android")) {
   69         // A plugin doesn't support the Android platform when this property isn't defined in the plugin.
   70         return
   71     }
   72     configureProject(project, outputDir)
   73 }
   74 
   75 String getFlutterRoot(Project project) {
   76     if (!project.hasProperty("flutter-root")) {
   77         throw new GradleException("The `-Pflutter-root` flag must be specified.")
   78     }
   79     return project.property("flutter-root")
   80 }
   81 
   82 void addAarTask(Project project, component) {
   83     String variantName = component.name.capitalize()
   84     String taskName = "assembleAar$variantName"
   85     project.tasks.create(name: taskName) {
   86         // This check is required to be able to configure the archives before `publish` runs.
   87         if (!project.gradle.startParameter.taskNames.contains(taskName)) {
   88             return
   89         }
   90 
   91         // Create a default MavenPublication for the variant (except "all" since that is used to publish artifacts in the new way)
   92         project.publishing.publications.create(component.name, MavenPublication) { pub ->
   93             groupId = "${pub.groupId}"
   94             artifactId = "${pub.artifactId}_${pub.name}"
   95             version = "${pub.version}"
   96             from component
   97         }
   98 
   99         // Generate the Maven artifacts.
  100         finalizedBy "publish"
  101     }
  102 }
  103 
  104 // maven-publish has to be applied _before_ the project gets evaluated, but some of the code in
  105 // `configureProject` requires the project to be evaluated. Apply the maven plugin to all projects, but
  106 // only configure it if it matches the conditions in `projectsEvaluated`
  107 
  108 allprojects {
  109    apply plugin: "maven-publish"
  110 }
  111 
  112 projectsEvaluated {
  113     assert rootProject.hasProperty("is-plugin")
  114     if (rootProject.property("is-plugin").toBoolean()) {
  115         assert rootProject.hasProperty("output-dir")
  116         // In plugin projects, the root project is the plugin.
  117         configureProject(rootProject, rootProject.property("output-dir"))
  118         return
  119     }
  120     // The module project is the `:flutter` subproject.
  121     Project moduleProject = rootProject.subprojects.find { it.name == "flutter" }
  122     assert moduleProject != null
  123     assert moduleProject.hasProperty("output-dir")
  124     configureProject(moduleProject, moduleProject.property("output-dir"))
  125 
  126     // Gets the plugin subprojects.
  127     Set<Project> modulePlugins = rootProject.subprojects.findAll {
  128         it.name != "flutter" && it.name != "app"
  129     }
  130     // When a module is built as a Maven artifacts, plugins must also be built this way
  131     // because the module POM's file will include a dependency on the plugin Maven artifact.
  132     // This is due to the Android Gradle Plugin expecting all library subprojects to be published
  133     // as Maven artifacts.
  134     modulePlugins.each { pluginProject ->
  135         configurePlugin(pluginProject, moduleProject.property("output-dir"))
  136         moduleProject.android.libraryVariants.all { variant ->
  137             // Configure the `assembleAar<variantName>` task for each plugin's projects and make
  138             // the module's equivalent task depend on the plugin's task.
  139             String variantName = variant.name.capitalize()
  140             moduleProject.tasks.findByPath("assembleAar$variantName")
  141                 .dependsOn(pluginProject.tasks.findByPath("assembleAar$variantName"))
  142         }
  143     }
  144 }