Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose resource generation task property in Gradle via compose.resources block #4564

Closed
paxbun opened this issue Apr 1, 2024 · 3 comments · Fixed by #5016
Closed

Expose resource generation task property in Gradle via compose.resources block #4564

paxbun opened this issue Apr 1, 2024 · 3 comments · Fixed by #5016
Assignees
Labels
enhancement New feature or request

Comments

@paxbun
Copy link
Contributor

paxbun commented Apr 1, 2024

For Kotlin compilation, we can access the compilation task via KotlinCompilation.compileTaskProvider property. Gradle plugins use this property to generate required Kotlin files before building.

Likewise, could you consider adding ResourcesExtension.resourceTaskProvider so users can make it depend on custom resource downloading tasks? It would be useful for those who have their own way of manging resources in their CI/CD pipeline.

We're downloading the required resource files from Azure Blob Storage and making the resource generation task depend on that download task so the download occurs during IDE import. We're achieving this like the following:

// downloads files from Azure Blob Storage
blobStorage {
  subscription = "..."
  accountName = "..."
  ...
  afterEvaluate {
    tasks.named("generateComposeResClass")
      .dependsOn(downloadTaskProvider /* from blobStorage block */)
    tasks.named("copyDebugFontsToAndroidAssets")
      .dependsOn(downloadTaskProvider)
    tasks.named("copyReleaseFontsToAndroidAssets")
      .dependsOn(downloadTaskProvider)
    tasks.named("syncComposeResourcesForIos")
      .dependsOn(downloadTaskProvider)
  }
}

and this is what we want to achieve:

// downloads files from Azure Blob Storage
blobStorage {
  subscription = "..."
  accountName = "..."
  ...
}

compose.resources {
  resourceTaskProvider.dependsOn(blobStorage.downloadTaskProvider)
}
@terrakok
Copy link
Collaborator

terrakok commented Apr 3, 2024

Why are you not able to use:

tasks.configureEach {
    if (name == "generateComposeResClass") {
        shouldRunAfter(blobStorage.downloadTaskProvider)
    }
}

@paxbun
Copy link
Contributor Author

paxbun commented Apr 3, 2024

@terrakok We can do that, and we're actually doing that (though we're using dependsOn), but I'm just requesting some statically-checked way to achieve the same thing.

For me, it would be best to be able to use properties like res or resources as in Android Gradle Plugin:

// like the following
android {
  sourceSets {
    getByName("main").res.srcDirs(...)
  }
}

val blobStorageDownloadDir = project.layout.buildDirectory.dir(...)
blobStorage {
  destination = blobStorageDownloadDir
}
compose.resources {
  dirs(blobStorageDownloadDir)
}

The existence of such a property entails that the user can run a task generating resources, and the resource packaging task must depend on that custom task. However, I think this needs more work and stabilizing more APIs, so I just requested a static property to access the resource syncing task.

As there are many people migrating their Android app to Compose Multiplatform (or KMP), I think providing similar features on the Gradle side as well will benefit more people.

@okushnikov
Copy link

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants