Skip to content

Commit d022a48

Browse files
committed
Improved ResourceConfigurationsPlugin KDoc.
1 parent 6a6069d commit d022a48

File tree

1 file changed

+49
-15
lines changed

1 file changed

+49
-15
lines changed

build-logic/src/main/kotlin/org/sdkotlin/buildlogic/plugins/resources/ResourceConfigurationsPlugin.kt

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,39 @@ import org.gradle.api.Project
1919
* Multiple configurations can be created via additional `create("<name>")`
2020
* calls.
2121
*
22-
* Each named configuration adds a source directory of the same name under
22+
* Multiple variants of a configuration can be created:
23+
*
24+
* ```kotlin
25+
* resourceConfigurations {
26+
* create("native") {
27+
* variants {
28+
* variant("linux") {
29+
* attributes {
30+
* [...]
31+
* }
32+
* }
33+
* variant("macos") {
34+
* attributes {
35+
* [...]
36+
* }
37+
* }
38+
* [...]
39+
* }
40+
* }
41+
* }
42+
* ```
43+
*
44+
* If no variants are declared, a default variant with the same name of the
45+
* configuration is added.
46+
*
47+
* Each variant by default adds a source directory of the same name under
2348
* 'src/main'. For a configuration named "special", it would be
2449
* 'src/main/special'. Any resources in this directory will be added as an
2550
* additional project output.
2651
*
27-
* Each configuration can define its own attributes for that project output,
28-
* enabling variant-aware consumption by other projects. By default, the
29-
* following attributes are set:
52+
* Each configuration and variant can define its own attributes for that project
53+
* artifact, enabling variant-aware consumption by other projects. By default,
54+
* the following attributes are set:
3055
* ```
3156
* org.gradle.category = library
3257
* org.gradle.dependency.bundling = external
@@ -43,10 +68,12 @@ import org.gradle.api.Project
4368
* ```kotlin
4469
* resourceConfigurations {
4570
* create("special") {
46-
* attribute(CATEGORY_ATTRIBUTE, objects.named(LIBRARY))
47-
* attribute(BUNDLING_ATTRIBUTE, objects.named(EXTERNAL))
48-
* attribute(LIBRARY_ELEMENTS_ATTRIBUTE, objects.named("something-else"))
49-
* attribute(USAGE_ATTRIBUTE, objects.named(JAVA_RUNTIME))
71+
* attributes {
72+
* attribute(CATEGORY_ATTRIBUTE, objects.named(LIBRARY))
73+
* attribute(BUNDLING_ATTRIBUTE, objects.named(EXTERNAL))
74+
* attribute(LIBRARY_ELEMENTS_ATTRIBUTE, objects.named("something-else"))
75+
* attribute(USAGE_ATTRIBUTE, objects.named(JAVA_RUNTIME))
76+
* }
5077
* }
5178
* }
5279
* ```
@@ -55,6 +82,9 @@ import org.gradle.api.Project
5582
* applied, and must be redeclared as needed. This is to ensure precise,
5683
* unambiguous definition of variants.
5784
*
85+
* Attributes declared for variants are appended to those used for the
86+
* configuration as a whole.
87+
*
5888
* A dependency handler extension is added to assist consuming projects in
5989
* declaring a dependency on the resource variant. For a resource configuration
6090
* named "special", the handler extension would be named
@@ -65,14 +95,18 @@ import org.gradle.api.Project
6595
* downstream consumers), and thereby available for tasks such as `test` and
6696
* `run`.
6797
*
68-
* Artifact views could then be used to select only the artifacts in
69-
* the runtime classpath that are from the named resource configuration, or to
98+
* Not that the dependency handler extension only adds the attributes for the
99+
* base configuration to the dependency declaration. Any additional attributes
100+
* for declared variants must be addressed by adding them to the respective
101+
* resolvable configurations, or via attribute compatibility and disambiguation
102+
* rules. This allows for artifact views to then be used to select only the
103+
* artifacts in the runtime classpath that are from a given variant, or to
70104
* select all the artifacts on the runtime classpath that are _not_ from the
71-
* named resource configuration. A use case for this may be for creating
72-
* distributions or generating installers where the resources are located
73-
* outside a typical 'lib' folder (e.g. in a 'conf/special' or 'bin/special'
74-
* folder), yet are still placed on the runtime classpath of the
75-
* application for portable, classpath-relative loading.
105+
* variant. A use case for this may be for creating distributions or generating
106+
* installers where the resources are located outside a typical 'lib' folder
107+
* (e.g. in a 'conf/special' or 'bin/special' folder), yet are still placed on
108+
* the runtime classpath of the application for portable, classpath-relative
109+
* loading.
76110
*/
77111
class ResourceConfigurationsPlugin : Plugin<Project> {
78112

0 commit comments

Comments
 (0)