Now that you mention it, I am using the Dark Reader extension which seemingly disabled syntax highlighting, so I assumed there was none for code blocks.
Seems like “extensions” was something already defined in the current context and since I named my variable “extensions” the first definition was shading it. This is why naming is important.
Right now I have this in my producer:
val extensionPath = Path("extensions/shared.rve")
val syncExtensionTask = tasks.register<Sync>("syncExtension") {
dependsOn("minifyReleaseWithR8")
from(layout.buildDirectory.file("intermediates/dex/release/minifyReleaseWithR8/classes.dex"))
into(layout.buildDirectory.dir("revanced/${extensionPath.parent.pathString}"))
rename("classes.dex", extensionPath.fileName.pathString)
}
val extensionDependencyScopeConfiguration by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = false
isVisible = false
}
val extensionConfiguration by configurations.creating {
isCanBeConsumed = true
isCanBeResolved = false
isVisible = false
extendsFrom(extensionDependencyScopeConfiguration)
}
artifacts.add(
extensionConfiguration.name,
layout.buildDirectory.dir("revanced"),
) {
builtBy(syncExtensionTask)
}
and this in my consumer:
val extensionsDependencyScopeConfiguration by configurations.dependencyScope("extensionDependencyScope")
val extensionsConfiguration = configurations.resolvable("extensionConfiguration") {
extendsFrom(extensionsDependencyScopeConfiguration)
}
sourceSets.main {
resources.srcDir(extensionsConfiguration)
}
dependencies {
extensionsDependencyScopeConfiguration(
project(
mapOf(
"path" to ":extensions:shared",
"configuration" to "extensionConfiguration",
),
),
)
}
This seems to work as expected. The artifact is being added where I need it. The way it is now though, I am unable to add new producers and automatically share their artifacts. I would need to change the consumer build script to do that. Each producer would have a configuration called extensionConfiguration
so I believe I need to iterate over all producers and depend on their configuration? Something like:
dependencies {
producers.forEach { producer ->
extensionsDependencyScopeConfiguration(
project(
mapOf(
"path" to producer,
"configuration" to "extensionConfiguration",
),
),
)
}
}
To add all the consumers automatically and depend on them I currently am doing this in my settings.gradle.kts file:
include(":patches")
file("extensions").listFiles()?.forEach { extension ->
include(":extensions:${extension.name}")
extension.listFiles()?.forEach { subExtension ->
if (subExtension.resolve("build.gradle.kts").exists()) {
include(":extensions:${extension.name}:${subExtension.name}")
}
}
}
As you can see, this is quite ugly. Is there any better approach to include projects automatically under a specific directory? My supplier projects may also depend on nested projects, so the current approach is not viable without recursively iterating through all nested directories, including the projects.
Once this is sorted out, I’ll consider the current forum post solved and proceed with a new one regarding setting up a plugin so that consumers do not have to specify the same blocks every time.