Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ public class LibraryArchRules implements ArchRulesService {

When authoring rules about the usage of your own library code, it is recommended to colocate your rules library in the
same project as the library code. The ArchRules plugin will publish the rules in a separate Jar, and the Runner plugin
will select that jar for running rules, but these rule classes will not end up up in the runtime classpath.
will select that jar for running rules, but these rule classes will not end up in the runtime classpath.

#### How it works

The Archrules Library plugin produces a separate Jar for the `archRules` sourceset, which is exposed as an alternate variant of the library.

## LICENSE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.netflix.nebula.archrules.gradle

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.attributes.Usage
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register

class ArchrulesLibraryPlugin : Plugin<Project> {
Expand All @@ -13,13 +15,21 @@ class ArchrulesLibraryPlugin : Plugin<Project> {
val ext = project.extensions.getByType<JavaPluginExtension>()
val archRulesSourceSet = ext.sourceSets.create("archRules")
val version = ArchrulesLibraryPlugin::class.java.`package`.implementationVersion ?: "latest.release"
project.dependencies.add(archRulesSourceSet.implementationConfigurationName,
project.dependencies.add(
archRulesSourceSet.implementationConfigurationName,
"com.netflix.nebula:nebula-archrules-core:$version"
)
val jarTask = project.tasks.register<Jar>("archRulesJar") {
archiveClassifier.set("archrules")
from(archRulesSourceSet.output)
}
val runtimeElements = project.configurations.getByName("runtimeElements")
runtimeElements.outgoing.variants.create("archRulesElements") {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named("arch-rules"))
}
artifact(jarTask)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,19 @@ class ArchrulesLibraryPluginTest {
assertThat(moduleMetadata)
.`as`("Gradle Module Metadata is created")
.exists()

val moduleMetadataJson = moduleMetadata.readText()
println(moduleMetadataJson)

assertThatJson(moduleMetadataJson)
.inPath("$.variants[?(@.name=='runtimeElements')].files[0]")
.isArray
.first().isObject
.containsEntry("name", "library-with-rules-0.0.1.jar")

assertThatJson(moduleMetadataJson)
.inPath("$.variants[?(@.name=='runtimeElementsArchRulesElements')].files[0]")
.isArray
.first().isObject
.containsEntry("name", "library-with-rules-0.0.1-archrules.jar")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ internal class IntegrationTest {

val result = runner.run("check") {
withGradleVersion(gradleVersion.version)
forwardOutput()
}

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