Skip to content

Commit 3ec54e1

Browse files
committed
An updated attempt to get the custom resource path out of the runtime classpath.
1 parent 92c69a1 commit 3ec54e1

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

build-logic/src/main/kotlin/org.sdkotlin.buildlogic.custom-resources-consumer.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import org.sdkotlin.buildlogic.artifacts.dsl.DependencyCreationExtension
22
import org.sdkotlin.buildlogic.attributes.CustomResources.CUSTOM_RESOURCE
3+
import org.sdkotlin.buildlogic.attributes.DefaultResourceAttributeRule
34
import org.sdkotlin.buildlogic.attributes.ResourceAttributeDependencyCreationExtension
45
import org.sdkotlin.buildlogic.attributes.ResourceAttributes.RESOURCE_ATTRIBUTE
56

@@ -11,6 +12,12 @@ dependencies {
1112
attribute(RESOURCE_ATTRIBUTE)
1213
}
1314

15+
components {
16+
// Add the resource attribute to all components with a default
17+
// value of "none".
18+
all<DefaultResourceAttributeRule>()
19+
}
20+
1421
// Add a `DependencyHandler` extension for declaring dependencies on
1522
// artifacts with "custom" resources attributes.
1623
extensions.add(

build-logic/src/main/kotlin/org/sdkotlin/buildlogic/attributes/ResourceAttributes.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.sdkotlin.buildlogic.attributes
22

33
import org.gradle.api.Named
4+
import org.gradle.api.artifacts.CacheableRule
5+
import org.gradle.api.artifacts.ComponentMetadataContext
6+
import org.gradle.api.artifacts.ComponentMetadataRule
47
import org.gradle.api.artifacts.Dependency
58
import org.gradle.api.artifacts.ProjectDependency
69
import org.gradle.api.artifacts.dsl.DependencyHandler
@@ -13,7 +16,9 @@ import org.gradle.api.attributes.LibraryElements.RESOURCES
1316
import org.gradle.api.model.ObjectFactory
1417
import org.gradle.kotlin.dsl.named
1518
import org.sdkotlin.buildlogic.artifacts.dsl.DependencyCreationExtension
19+
import org.sdkotlin.buildlogic.attributes.ResourceAttributes.RESOURCE_ATTRIBUTE
1620
import org.sdkotlin.buildlogic.attributes.ResourceAttributes.applyResourceAttributes
21+
import javax.inject.Inject
1722

1823
/**
1924
* An attribute type for resource variants.
@@ -78,3 +83,18 @@ class ResourceAttributeDependencyCreationExtension(
7883
return dependency
7984
}
8085
}
86+
87+
@CacheableRule
88+
abstract class DefaultResourceAttributeRule : ComponentMetadataRule {
89+
90+
@get:Inject
91+
abstract val objects: ObjectFactory
92+
93+
override fun execute(context: ComponentMetadataContext) {
94+
context.details.allVariants {
95+
attributes {
96+
attributes.attribute(RESOURCE_ATTRIBUTE, objects.named("none"))
97+
}
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)