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
21 changes: 11 additions & 10 deletions src/main/kotlin/nebula/plugin/resolutionrules/plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,8 @@ class ResolutionRulesPlugin : Plugin<Project> {
project.extensions.create("nebulaResolutionRules", NebulaResolutionRulesExtension::class.java, project)
addRulesFromProjectProperties(project, extension)
val rootProject = project.rootProject
val configuration = project.configurations.maybeCreate(RESOLUTION_RULES_CONFIG_NAME)
if (project != rootProject) {
configuration.isCanBeConsumed = false
val rootProjectDependency = project.dependencies.project(
mapOf("path" to rootProject.path, "configuration" to RESOLUTION_RULES_CONFIG_NAME)
)
configuration.withDependencies { dependencies ->
dependencies.add(rootProjectDependency)
}
configuration.attributes {
val configuration = project.configurations.create(RESOLUTION_RULES_CONFIG_NAME) {
it.attributes {
it.attribute(
Usage.USAGE_ATTRIBUTE,
project.objects.named(Usage::class.java, Usage.JAVA_RUNTIME)
Expand All @@ -103,6 +95,15 @@ class ResolutionRulesPlugin : Plugin<Project> {
)
}
}
if (project != rootProject) {
configuration.isCanBeConsumed = false
val rootProjectDependency = project.dependencies.project(
mapOf("path" to rootProject.path, "configuration" to RESOLUTION_RULES_CONFIG_NAME)
)
configuration.withDependencies { dependencies ->
dependencies.add(rootProjectDependency)
}
}
if (rootProject.extensions.findByType(NebulaResolutionRulesExtension::class.java) == null) {
rootProject.extensions.create(
"nebulaResolutionRules",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,38 @@ internal class ResolutionRulesPluginTest {
)
assertThat(diResult.output)
.contains("Variant runtimeElements:")
.containsIgnoringWhitespaces("| org.gradle.category | library | library |")
.containsIgnoringWhitespaces("| org.gradle.libraryelements | jar | classes+resources |")
.containsIgnoringWhitespaces("| org.gradle.usage | java-runtime | java-runtime |")
}

@Test
fun `resolutionRules configuration can resolve a library dependency in root with newer java version`() {
val runner = testProject(projectDir) {
rootProject {
plugins {
id("java")
id("com.netflix.nebula.resolution-rules")
}
javaToolchain(8)
repositories {
mavenCentral()
}
dependencies {
add("resolutionRules", "com.netflix.nebula:nebula-test:latest.release")
}
}
}

val rootDiResult = runner.run(
"dependencyInsight",
"--configuration", "resolutionRules",
"--dependency", "nebula-test"
)
assertThat(rootDiResult.output)
.contains("Variant runtimeElements:")
.containsIgnoringWhitespaces("| org.gradle.category | library | library |")
.containsIgnoringWhitespaces("| org.gradle.libraryelements | jar | classes+resources |")
.containsIgnoringWhitespaces("| org.gradle.usage | java-runtime | java-runtime |")
}
}
Loading