Skip to content

Commit 7197f6f

Browse files
committed
Library plugin should add dependency on core library using major version only
The plugin should add dependencies on the core library of the same version. However, there are 2 edge cases: 1) tests, where jar packaging with a version has not been done 2) the core library is published to maven central, whereas the plugin is published to Gradle Plugin Portal. Maven central has a much longer delay, so for a while, there is a state where the plugin ios available, but the corresponding core library is not yet available. In this case, we can match to the latest version of the same major version, which will solve the problem for any users who use dynamic minor or patch versions.
1 parent 82d9d03 commit 7197f6f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import org.gradle.kotlin.dsl.support.serviceOf
2222
import org.gradle.testing.base.TestingExtension
2323

2424
class ArchrulesLibraryPlugin : Plugin<Project> {
25+
2526
override fun apply(project: Project) {
26-
val version = ArchrulesLibraryPlugin::class.java.`package`.implementationVersion ?: "latest.release"
27+
val version = determineVersion()
2728
project.pluginManager.withPlugin("java") {
2829
val ext = project.extensions.getByType<JavaPluginExtension>()
2930
val archRulesSourceSet = ext.sourceSets.create("archRules")
@@ -98,4 +99,24 @@ class ArchrulesLibraryPlugin : Plugin<Project> {
9899
)
99100
}
100101
}
102+
103+
/**
104+
* The plugin should add dependencies on the core library of the same version
105+
* However, there are 2 edge cases:
106+
* 1) tests, where jar packaging with a version has not been done
107+
* 2) the core library is published to maven central, whereas the plugin is published to Gradle Plugin Portal.
108+
* Maven central has a much longer delay, so for a while, there is a state where the plugin ios available,
109+
* but the corresponding core library is not yet available.
110+
* In this case, we can match to the latest version of the same major version,
111+
* which will solve the problem for any users who use dynamic minor or patch versions.
112+
*/
113+
fun determineVersion(): String {
114+
val metadataVersion = ArchrulesLibraryPlugin::class.java.`package`.implementationVersion
115+
if (metadataVersion == null) {
116+
return "latest.release" // this happens in tests
117+
} else {
118+
val majorVersion = metadataVersion.substringBefore(".")
119+
return "$majorVersion.+" // in case maven central is behind GPP
120+
}
121+
}
101122
}

0 commit comments

Comments
 (0)