Skip to content

Commit

Permalink
Multiversion JGit
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob committed Sep 14, 2024
1 parent 4ee9310 commit f383029
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ svnkit = "1.10.11"
# Version history: https://mvnrepository.com/artifact/org.eclipse.jgit/org.eclipse.jgit
# Changelog (Full): https://projects.eclipse.org/projects/technology.jgit
# Changelog (Summary): https://wiki.eclipse.org/JGit/New_and_Noteworthy
jgit = "7.0.0.202409031743-r"
jgit11 = "6.10.0.202406032230-r"
jgit17 = "7.0.0.202409031743-r"

# Explicitly using an outdated version of diffuse, don't remember why.
# Versions: https://github.com/JakeWharton/diffuse/tags
Expand Down Expand Up @@ -140,7 +141,8 @@ jfixture-kotlin = { module = "com.flextrade.jfixture:kfixture", version.ref = "j

svnkit = { module = "org.tmatesoft.svnkit:svnkit", version.ref = "svnkit" }
svnkit-cli = { module = "org.tmatesoft.svnkit:svnkit-cli", version.ref = "svnkit" }
jgit = { module = "org.eclipse.jgit:org.eclipse.jgit", version.ref = "jgit" }
jgit11 = { module = "org.eclipse.jgit:org.eclipse.jgit", version.ref = "jgit11" }
jgit17 = { module = "org.eclipse.jgit:org.eclipse.jgit", version.ref = "jgit17" }
violations = { module = "se.bjurr.violations:violations-lib", version.ref = "violations" }
dexMemberList = { module = "com.jakewharton.dex:dex-member-list", version.ref = "diffuse" }

Expand Down
53 changes: 51 additions & 2 deletions plugin/versioning/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies {
implementation(projects.compat.agp)
implementation(libs.svnkit)
implementation(libs.svnkit.cli)
implementation(libs.jgit)
compileOnly(libs.jgit17)
compileOnly(libs.android.gradle)

// This plugin is part of the net.twisterrob.gradle.plugin.android-app plugin, not designed to work on its own.
Expand All @@ -50,5 +50,54 @@ dependencies {
}

testFixturesApi(libs.svnkit)
testFixturesApi(libs.jgit)
testFixturesApi(libs.jgit17)
}

val runtimeElementsJava11 by configurations.creating {
this.extendsFrom(configurations.runtimeElements.get())
val other = configurations.runtimeElements.get().attributes
attributes {
other.keySet().forEach {
@Suppress("UNCHECKED_CAST")
attribute(it as Attribute<Any>, other.getAttribute(it)!!)
}
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 11)
}
}

val runtimeElementsJava17 by configurations.creating {
this.extendsFrom(configurations.runtimeElements.get())
val other = configurations.runtimeElements.get().attributes
attributes {
other.keySet().forEach {
@Suppress("UNCHECKED_CAST")
attribute(it as Attribute<Any>, other.getAttribute(it)!!)
}
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 17)
}
}

configurations.runtimeElements {
attributes {
attribute(Attribute.of("reject", String::class.java), "yes")
}
}

dependencies {
constraints {
runtimeElementsJava11(libs.jgit11) {
because("JGit 6.10.0 is the last version to support Java 11. JGit 7.x requires Java 17.")
versionConstraint.rejectedVersions.add("[7.0,)")
}
runtimeElementsJava17(libs.jgit17) {
because("JGit 7.x is the first version to require Java 17.")
versionConstraint.rejectedVersions.add("(,7.0)")
}
}
}

components.getByName<AdhocComponentWithVariants>("java") {
withVariantsFromConfiguration(configurations.runtimeElements.get()) { skip() }
addVariantsFromConfiguration(runtimeElementsJava11) {}
addVariantsFromConfiguration(runtimeElementsJava17) {}
}

0 comments on commit f383029

Please sign in to comment.