Skip to content

Commit 79b5c59

Browse files
committed
Consolidated the custom resources logic to a single precompiled script plugin.
1 parent d5398b7 commit 79b5c59

File tree

7 files changed

+131
-128
lines changed

7 files changed

+131
-128
lines changed

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

Lines changed: 0 additions & 18 deletions
This file was deleted.

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

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import gradle.kotlin.dsl.accessors._0defa1a7b298cc792e0089bd5fae3b0a.runtimeClasspath
2+
import org.gradle.api.artifacts.type.ArtifactTypeDefinition.JVM_RESOURCES_DIRECTORY
3+
import org.gradle.api.attributes.LibraryElements.CLASSES_AND_RESOURCES
4+
import org.sdkotlin.buildlogic.artifacts.dsl.DependencyCreationExtension
5+
import org.sdkotlin.buildlogic.attributes.CustomResources.CUSTOM_RESOURCES
6+
import org.sdkotlin.buildlogic.attributes.LibraryElementsAttributeDependencyCreationExtension
7+
import org.sdkotlin.buildlogic.attributes.LibraryElementsAttributes.applyLibraryElementsAttributes
8+
9+
@Suppress("UnstableApiUsage")
10+
configurations {
11+
12+
// Create a variant-aware consumable configuration for "custom resources"
13+
// artifacts.
14+
consumable("customElements") {
15+
attributes {
16+
applyLibraryElementsAttributes(objects, CUSTOM_RESOURCES)
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
23+
// Add a `DependencyHandler` extension for declaring a dependency on
24+
// the "custom resources" artifact variant.
25+
extensions.add(
26+
DependencyCreationExtension::class.java,
27+
"customResources",
28+
LibraryElementsAttributeDependencyCreationExtension(
29+
dependencyHandler = this,
30+
objects = objects,
31+
libraryElementsAttributeValue = CUSTOM_RESOURCES
32+
)
33+
)
34+
}
35+
36+
artifacts {
37+
38+
// Any files in "src/main/custom" are custom resources.
39+
val customResourceDirectory: Directory =
40+
project.layout.projectDirectory.dir("src/main/custom")
41+
42+
// No build step is necessary, so directly add the directory as an
43+
// artifact to the variant-aware consumable configuration (if it exists).
44+
if (customResourceDirectory.asFile.exists()) {
45+
add("customElements", customResourceDirectory) {
46+
type = JVM_RESOURCES_DIRECTORY
47+
}
48+
}
49+
}
50+
51+
tasks {
52+
53+
register<PrintClasspath>("printRuntimeClasspath") {
54+
55+
group = "custom-resources"
56+
description = "Prints the runtime classpath"
57+
58+
classpathName = "runtimeClasspath"
59+
60+
classpath = provider {
61+
configurations.runtimeClasspath.get()
62+
}
63+
}
64+
65+
register<PrintClasspath>("printCustomResourcesClasspath") {
66+
67+
group = "custom-resources"
68+
description =
69+
"Prints the custom resources subset of the runtime classpath"
70+
71+
classpathName = "customResourcesClasspath"
72+
73+
classpath = provider {
74+
configurations.runtimeClasspath.get().incoming.artifactView {
75+
76+
@Suppress("UnstableApiUsage")
77+
withVariantReselection()
78+
79+
attributes {
80+
applyLibraryElementsAttributes(objects, CUSTOM_RESOURCES)
81+
}
82+
}.files
83+
}
84+
}
85+
86+
register<PrintClasspath>("printRuntimeClasspathWithoutCustomResources") {
87+
88+
group = "custom-resources"
89+
description =
90+
"Prints the runtime classpath without the custom resources"
91+
92+
classpathName = "runtimeClasspathWithoutCustomResources"
93+
94+
classpath = provider {
95+
configurations.runtimeClasspath.get().incoming.artifactView {
96+
97+
@Suppress("UnstableApiUsage")
98+
withVariantReselection()
99+
100+
attributes {
101+
applyLibraryElementsAttributes(objects,
102+
CLASSES_AND_RESOURCES)
103+
}
104+
}.files
105+
}
106+
}
107+
}
108+
109+
@CacheableTask
110+
abstract class PrintClasspath : DefaultTask() {
111+
112+
@get:Input
113+
abstract val classpathName: Property<String>
114+
115+
@get:Classpath
116+
abstract val classpath: Property<FileCollection>
117+
118+
@TaskAction
119+
fun printClasspath() {
120+
121+
val classpathAsPath = classpath.get().asPath
122+
123+
val wrappedClasspath = classpathAsPath.replace(":", "\n")
124+
125+
logger.lifecycle("${classpathName.get()}: \n$wrappedClasspath")
126+
}
127+
}
Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import org.gradle.api.attributes.LibraryElements.CLASSES_AND_RESOURCES
21
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3-
import org.sdkotlin.buildlogic.attributes.CustomResources.CUSTOM_RESOURCES
4-
import org.sdkotlin.buildlogic.attributes.LibraryElementsAttributes.applyLibraryElementsAttributes
52

63
plugins {
74
kotlin("jvm")
@@ -25,6 +22,7 @@ jvmDependencyConflicts {
2522
}
2623

2724
tasks {
25+
2826
withType<JavaCompile>().configureEach {
2927

3028
with(options) {
@@ -50,80 +48,4 @@ tasks {
5048
)
5149
}
5250
}
53-
54-
register("printCustomResourcesClasspath") {
55-
56-
group = "custom-resources"
57-
description =
58-
"Prints the custom resources subset of the runtime classpath"
59-
60-
val fileCollection: Provider<FileCollection> = provider {
61-
configurations.runtimeClasspath.get().incoming.artifactView {
62-
63-
@Suppress("UnstableApiUsage")
64-
withVariantReselection()
65-
66-
attributes {
67-
applyLibraryElementsAttributes(objects, CUSTOM_RESOURCES)
68-
}
69-
}.files
70-
}
71-
72-
doLast {
73-
74-
val classpathAsPath = fileCollection.get().asPath
75-
76-
val wrappedClasspath = classpathAsPath.replace(":", "\n")
77-
78-
println("wrappedClasspath: \n$wrappedClasspath")
79-
}
80-
}
81-
82-
register("printRuntimeClasspathWithoutCustomResources") {
83-
84-
group = "custom-resources"
85-
description =
86-
"Prints the runtime classpath without the custom resources"
87-
88-
val fileCollection: Provider<FileCollection> = provider {
89-
configurations.runtimeClasspath.get().incoming.artifactView {
90-
91-
@Suppress("UnstableApiUsage")
92-
withVariantReselection()
93-
94-
attributes {
95-
applyLibraryElementsAttributes(objects,
96-
CLASSES_AND_RESOURCES)
97-
}
98-
}.files
99-
}
100-
101-
doLast {
102-
103-
val classpathAsPath = fileCollection.get().asPath
104-
105-
val wrappedClasspath = classpathAsPath.replace(":", "\n")
106-
107-
println("wrappedClasspath: \n$wrappedClasspath")
108-
}
109-
}
110-
111-
register("printRuntimeClasspath") {
112-
113-
group = "custom-resources"
114-
description = "Prints the runtime classpath"
115-
116-
val fileCollection: Provider<FileCollection> = provider {
117-
configurations.runtimeClasspath.get()
118-
}
119-
120-
doLast {
121-
122-
val classpathAsPath = fileCollection.get().asPath
123-
124-
val wrappedClasspath = classpathAsPath.replace(":", "\n")
125-
126-
println("wrappedClasspath: \n$wrappedClasspath")
127-
}
128-
}
12951
}

subprojects/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
application
33
alias(libs.plugins.springboot.plugin)
4-
id("org.sdkotlin.buildlogic.custom-resources-consumer")
4+
id("org.sdkotlin.buildlogic.custom-resources")
55
id("org.sdkotlin.buildlogic.spring-project")
66
id("org.sdkotlin.buildlogic.test.integration-test-suite")
77
}

subprojects/custom-resources-intermediary/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
plugins {
22
id("org.sdkotlin.buildlogic.kotlin-project")
3-
id("org.sdkotlin.buildlogic.custom-resources-consumer")
3+
id("org.sdkotlin.buildlogic.custom-resources")
44
}
55

66
description =
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id("org.sdkotlin.buildlogic.custom-resources-producer")
2+
id("org.sdkotlin.buildlogic.custom-resources")
33
}
44

55
description = "Contains custom resources."

0 commit comments

Comments
 (0)