Skip to content

Commit 63c3b45

Browse files
archrules library plugin should produce an outgoing variant for the archrules jar
Co-authored-by: Emily Yuan <[email protected]>
1 parent 88cadb9 commit 63c3b45

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ public class LibraryArchRules implements ArchRulesService {
6464

6565
When authoring rules about the usage of your own library code, it is recommended to colocate your rules library in the
6666
same project as the library code. The ArchRules plugin will publish the rules in a separate Jar, and the Runner plugin
67-
will select that jar for running rules, but these rule classes will not end up up in the runtime classpath.
67+
will select that jar for running rules, but these rule classes will not end up in the runtime classpath.
68+
69+
#### How it works
70+
71+
The Archrules Library plugin produces a separate Jar for the `archRules` sourceset, which is exposed as an alternate variant of the library.
6872

6973
## LICENSE
7074

nebula-archrules-gradle-plugin/src/main/kotlin/com/netflix/nebula/archrules/gradle/ArchrulesLibraryPlugin.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package com.netflix.nebula.archrules.gradle
22

33
import org.gradle.api.Plugin
44
import org.gradle.api.Project
5+
import org.gradle.api.attributes.Usage
56
import org.gradle.api.plugins.JavaPluginExtension
67
import org.gradle.jvm.tasks.Jar
78
import org.gradle.kotlin.dsl.getByType
9+
import org.gradle.kotlin.dsl.named
810
import org.gradle.kotlin.dsl.register
911

1012
class ArchrulesLibraryPlugin : Plugin<Project> {
@@ -13,13 +15,21 @@ class ArchrulesLibraryPlugin : Plugin<Project> {
1315
val ext = project.extensions.getByType<JavaPluginExtension>()
1416
val archRulesSourceSet = ext.sourceSets.create("archRules")
1517
val version = ArchrulesLibraryPlugin::class.java.`package`.implementationVersion ?: "latest.release"
16-
project.dependencies.add(archRulesSourceSet.implementationConfigurationName,
18+
project.dependencies.add(
19+
archRulesSourceSet.implementationConfigurationName,
1720
"com.netflix.nebula:nebula-archrules-core:$version"
1821
)
1922
val jarTask = project.tasks.register<Jar>("archRulesJar") {
2023
archiveClassifier.set("archrules")
2124
from(archRulesSourceSet.output)
2225
}
26+
val runtimeElements = project.configurations.getByName("runtimeElements")
27+
runtimeElements.outgoing.variants.create("archRulesElements") {
28+
attributes {
29+
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named("arch-rules"))
30+
}
31+
artifact(jarTask)
32+
}
2333
}
2434
}
2535
}

nebula-archrules-gradle-plugin/src/test/kotlin/com/netflix/nebula/archrules/gradle/ArchrulesLibraryPluginTest.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,19 @@ class ArchrulesLibraryPluginTest {
8383
assertThat(moduleMetadata)
8484
.`as`("Gradle Module Metadata is created")
8585
.exists()
86+
8687
val moduleMetadataJson = moduleMetadata.readText()
87-
println(moduleMetadataJson)
88+
8889
assertThatJson(moduleMetadataJson)
8990
.inPath("$.variants[?(@.name=='runtimeElements')].files[0]")
9091
.isArray
9192
.first().isObject
9293
.containsEntry("name", "library-with-rules-0.0.1.jar")
9394

95+
assertThatJson(moduleMetadataJson)
96+
.inPath("$.variants[?(@.name=='runtimeElementsArchRulesElements')].files[0]")
97+
.isArray
98+
.first().isObject
99+
.containsEntry("name", "library-with-rules-0.0.1-archrules.jar")
94100
}
95101
}

nebula-archrules-gradle-plugin/src/test/kotlin/com/netflix/nebula/archrules/gradle/IntegrationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ internal class IntegrationTest {
4949

5050
val result = runner.run("check") {
5151
withGradleVersion(gradleVersion.version)
52+
forwardOutput()
5253
}
5354

5455
assertThat(result.task(":library-with-rules:check"))

0 commit comments

Comments
 (0)