mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-25 17:40:30 +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:
parent
95d3b646b2
commit
cf6ec8c28f
@ -10,9 +10,11 @@ import org.gradle.api.GradleException
|
||||
import org.gradle.api.NamedDomainObjectProvider
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.artifacts.Dependency
|
||||
import org.gradle.api.attributes.TestSuiteType
|
||||
import org.gradle.api.file.FileSystemOperations
|
||||
import org.gradle.api.plugins.JavaPluginExtension
|
||||
import org.gradle.api.provider.ListProperty
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.provider.SetProperty
|
||||
import org.gradle.api.reporting.ReportingExtension
|
||||
@ -73,11 +75,17 @@ abstract class CCTweakedExtension(
|
||||
*/
|
||||
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. */
|
||||
val sourceSets = sourceDirectories.map { x -> x.map { it.sourceSet } }
|
||||
|
||||
init {
|
||||
sourceDirectories.finalizeValueOnRead()
|
||||
excludedDeps.finalizeValueOnRead()
|
||||
project.afterEvaluate { sourceDirectories.disallowChanges() }
|
||||
}
|
||||
|
||||
@ -246,6 +254,20 @@ abstract class CCTweakedExtension(
|
||||
).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 {
|
||||
private val COMMIT_COUNTS = Pattern.compile("""^\s*[0-9]+\s+(.*)$""")
|
||||
private val IGNORED_USERS = setOf(
|
||||
|
@ -6,6 +6,8 @@ package cc.tweaked.gradle
|
||||
|
||||
import org.gradle.api.artifacts.Dependency
|
||||
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.specs.Spec
|
||||
|
||||
@ -26,8 +28,13 @@ class MavenDependencySpec {
|
||||
|
||||
fun exclude(dep: Dependency) {
|
||||
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.name.isNullOrEmpty() || dep.name == it.artifactId) &&
|
||||
(name.isNullOrEmpty() || name == it.artifactId) &&
|
||||
(dep.version.isNullOrEmpty() || dep.version == it.version)
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ addRemappedConfiguration("testWithIris")
|
||||
|
||||
dependencies {
|
||||
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) {
|
||||
exclude("net.fabricmc", "fabric-loader")
|
||||
exclude("net.fabricmc.fabric-api")
|
||||
@ -72,9 +72,9 @@ dependencies {
|
||||
include(libs.nightConfig.toml)
|
||||
|
||||
// Pull in our other projects. See comments in MinecraftConfigurations on this nastiness.
|
||||
api(commonClasses(project(":fabric-api")))
|
||||
clientApi(clientClasses(project(":fabric-api")))
|
||||
implementation(project(":core"))
|
||||
api(commonClasses(project(":fabric-api"))) { cct.exclude(this) }
|
||||
clientApi(clientClasses(project(":fabric-api"))) { cct.exclude(this) }
|
||||
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
|
||||
// in our POM, and this is the easiest way.
|
||||
runtimeOnly(libs.cobalt)
|
||||
@ -168,7 +168,11 @@ loom {
|
||||
configureForGameTest(this)
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
@ -258,9 +262,7 @@ publishing {
|
||||
publications {
|
||||
named("maven", MavenPublication::class) {
|
||||
mavenDependencies {
|
||||
exclude(dependencies.create("cc.tweaked:"))
|
||||
exclude(libs.jei.fabric.get())
|
||||
exclude(libs.modmenu.get())
|
||||
cct.configureExcludes(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,9 +131,9 @@ dependencies {
|
||||
libs.bundles.externalMods.forge.runtime.get().map { runtimeOnly(fg.deobf(it)) }
|
||||
|
||||
// Depend on our other projects.
|
||||
api(commonClasses(project(":forge-api")))
|
||||
api(clientClasses(project(":forge-api")))
|
||||
implementation(project(":core"))
|
||||
api(commonClasses(project(":forge-api"))) { cct.exclude(this) }
|
||||
clientApi(clientClasses(project(":forge-api"))) { cct.exclude(this) }
|
||||
implementation(project(":core")) { cct.exclude(this) }
|
||||
|
||||
minecraftEmbed(libs.cobalt) {
|
||||
jarJar.ranged(this, "[${libs.versions.cobalt.asProvider().get()},${libs.versions.cobalt.next.get()})")
|
||||
@ -254,7 +254,7 @@ publishing {
|
||||
artifact(tasks.jarJar)
|
||||
|
||||
mavenDependencies {
|
||||
exclude(dependencies.create("cc.tweaked:"))
|
||||
cct.configureExcludes(this)
|
||||
exclude(libs.jei.forge.get())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user