1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-26 18:10:29 +00:00

Add a slightly cleaner system for excluding deps

Previously we prevented our published full jar depending on any of the
other projects by excluding the whole cc.tweaked jar. However, as Cobalt
also now lives in that group, this meant we were missing the Cobalt
dependency.

Rather than specifying a wildcard, we now exclude the dependencies when
adding them to the project.
This commit is contained in:
Jonathan Coates 2023-12-16 22:35:11 +00:00
parent 95d3b646b2
commit cf6ec8c28f
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
4 changed files with 44 additions and 13 deletions

View File

@ -10,9 +10,11 @@ import org.gradle.api.GradleException
import org.gradle.api.NamedDomainObjectProvider import org.gradle.api.NamedDomainObjectProvider
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.Task import org.gradle.api.Task
import org.gradle.api.artifacts.Dependency
import org.gradle.api.attributes.TestSuiteType import org.gradle.api.attributes.TestSuiteType
import org.gradle.api.file.FileSystemOperations import org.gradle.api.file.FileSystemOperations
import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Provider import org.gradle.api.provider.Provider
import org.gradle.api.provider.SetProperty import org.gradle.api.provider.SetProperty
import org.gradle.api.reporting.ReportingExtension import org.gradle.api.reporting.ReportingExtension
@ -73,11 +75,17 @@ abstract class CCTweakedExtension(
*/ */
val sourceDirectories: SetProperty<SourceSetReference> = project.objects.setProperty(SourceSetReference::class.java) val sourceDirectories: SetProperty<SourceSetReference> = project.objects.setProperty(SourceSetReference::class.java)
/**
* Dependencies excluded from published artifacts.
*/
private val excludedDeps: ListProperty<Dependency> = project.objects.listProperty(Dependency::class.java)
/** All source sets referenced by this project. */ /** All source sets referenced by this project. */
val sourceSets = sourceDirectories.map { x -> x.map { it.sourceSet } } val sourceSets = sourceDirectories.map { x -> x.map { it.sourceSet } }
init { init {
sourceDirectories.finalizeValueOnRead() sourceDirectories.finalizeValueOnRead()
excludedDeps.finalizeValueOnRead()
project.afterEvaluate { sourceDirectories.disallowChanges() } project.afterEvaluate { sourceDirectories.disallowChanges() }
} }
@ -246,6 +254,20 @@ abstract class CCTweakedExtension(
).resolve().single() ).resolve().single()
} }
/**
* Exclude a dependency from being publisehd in Maven.
*/
fun exclude(dep: Dependency) {
excludedDeps.add(dep)
}
/**
* Configure a [MavenDependencySpec].
*/
fun configureExcludes(spec: MavenDependencySpec) {
for (dep in excludedDeps.get()) spec.exclude(dep)
}
companion object { companion object {
private val COMMIT_COUNTS = Pattern.compile("""^\s*[0-9]+\s+(.*)$""") private val COMMIT_COUNTS = Pattern.compile("""^\s*[0-9]+\s+(.*)$""")
private val IGNORED_USERS = setOf( private val IGNORED_USERS = setOf(

View File

@ -6,6 +6,8 @@ package cc.tweaked.gradle
import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.MinimalExternalModuleDependency import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.plugins.BasePluginExtension
import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.specs.Spec import org.gradle.api.specs.Spec
@ -26,8 +28,13 @@ class MavenDependencySpec {
fun exclude(dep: Dependency) { fun exclude(dep: Dependency) {
exclude { exclude {
// We have to cheat a little for project dependencies, as the project name doesn't match the artifact group.
val name = when (dep) {
is ProjectDependency -> dep.dependencyProject.extensions.getByType(BasePluginExtension::class.java).archivesName.get()
else -> dep.name
}
(dep.group.isNullOrEmpty() || dep.group == it.groupId) && (dep.group.isNullOrEmpty() || dep.group == it.groupId) &&
(dep.name.isNullOrEmpty() || dep.name == it.artifactId) && (name.isNullOrEmpty() || name == it.artifactId) &&
(dep.version.isNullOrEmpty() || dep.version == it.version) (dep.version.isNullOrEmpty() || dep.version == it.version)
} }
} }

View File

@ -48,7 +48,7 @@ addRemappedConfiguration("testWithIris")
dependencies { dependencies {
clientCompileOnly(variantOf(libs.emi) { classifier("api") }) clientCompileOnly(variantOf(libs.emi) { classifier("api") })
modImplementation(libs.bundles.externalMods.fabric) modImplementation(libs.bundles.externalMods.fabric) { cct.exclude(this) }
modCompileOnly(libs.bundles.externalMods.fabric.compile) { modCompileOnly(libs.bundles.externalMods.fabric.compile) {
exclude("net.fabricmc", "fabric-loader") exclude("net.fabricmc", "fabric-loader")
exclude("net.fabricmc.fabric-api") exclude("net.fabricmc.fabric-api")
@ -72,9 +72,9 @@ dependencies {
include(libs.nightConfig.toml) include(libs.nightConfig.toml)
// Pull in our other projects. See comments in MinecraftConfigurations on this nastiness. // Pull in our other projects. See comments in MinecraftConfigurations on this nastiness.
api(commonClasses(project(":fabric-api"))) api(commonClasses(project(":fabric-api"))) { cct.exclude(this) }
clientApi(clientClasses(project(":fabric-api"))) clientApi(clientClasses(project(":fabric-api"))) { cct.exclude(this) }
implementation(project(":core")) implementation(project(":core")) { cct.exclude(this) }
// These are transitive deps of :core, so we don't need these deps. However, we want them to appear as runtime deps // These are transitive deps of :core, so we don't need these deps. However, we want them to appear as runtime deps
// in our POM, and this is the easiest way. // in our POM, and this is the easiest way.
runtimeOnly(libs.cobalt) runtimeOnly(libs.cobalt)
@ -168,7 +168,11 @@ loom {
configureForGameTest(this) configureForGameTest(this)
property("fabric-api.gametest") property("fabric-api.gametest")
property("fabric-api.gametest.report-file", layout.buildDirectory.dir("test-results/runGametest.xml").getAbsolutePath()) property(
"fabric-api.gametest.report-file",
layout.buildDirectory.dir("test-results/runGametest.xml")
.getAbsolutePath(),
)
runDir("run/gametest") runDir("run/gametest")
} }
} }
@ -258,9 +262,7 @@ publishing {
publications { publications {
named("maven", MavenPublication::class) { named("maven", MavenPublication::class) {
mavenDependencies { mavenDependencies {
exclude(dependencies.create("cc.tweaked:")) cct.configureExcludes(this)
exclude(libs.jei.fabric.get())
exclude(libs.modmenu.get())
} }
} }
} }

View File

@ -131,9 +131,9 @@ dependencies {
libs.bundles.externalMods.forge.runtime.get().map { runtimeOnly(fg.deobf(it)) } libs.bundles.externalMods.forge.runtime.get().map { runtimeOnly(fg.deobf(it)) }
// Depend on our other projects. // Depend on our other projects.
api(commonClasses(project(":forge-api"))) api(commonClasses(project(":forge-api"))) { cct.exclude(this) }
api(clientClasses(project(":forge-api"))) clientApi(clientClasses(project(":forge-api"))) { cct.exclude(this) }
implementation(project(":core")) implementation(project(":core")) { cct.exclude(this) }
minecraftEmbed(libs.cobalt) { minecraftEmbed(libs.cobalt) {
jarJar.ranged(this, "[${libs.versions.cobalt.asProvider().get()},${libs.versions.cobalt.next.get()})") jarJar.ranged(this, "[${libs.versions.cobalt.asProvider().get()},${libs.versions.cobalt.next.get()})")
@ -254,7 +254,7 @@ publishing {
artifact(tasks.jarJar) artifact(tasks.jarJar)
mavenDependencies { mavenDependencies {
exclude(dependencies.create("cc.tweaked:")) cct.configureExcludes(this)
exclude(libs.jei.forge.get()) exclude(libs.jei.forge.get())
} }
} }