From 728f2ea5970358de2033d6ee8419707d3a7ae775 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 8 Feb 2024 10:05:01 +0100 Subject: [PATCH] Infer module dependencies from MCVersion --- build.gradle | 66 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index deb221d00..c303a742d 100644 --- a/build.gradle +++ b/build.gradle @@ -64,6 +64,32 @@ def getProjectMavenName(project) { return simpleName } + + +static def getMCRange(Project project) { + def predicates = [] + + if (project.hasProperty("minVersionIncluded")) { + predicates.add(">=${VersionHelper.parseVersion(project["minVersionIncluded"]).friendlyString}") + } + + if (project.hasProperty("minVersionExcluded")) { + predicates.add(">${VersionHelper.parseVersion(project["minVersionExcluded"]).friendlyString}") + } + + if (project.hasProperty("maxVersionIncluded")) { + predicates.add("<=${VersionHelper.parseVersion(project["maxVersionIncluded"]).friendlyString}") + } + + if (project.hasProperty("maxVersionExcluded")) { + predicates.add("<${VersionHelper.parseVersion(project["maxVersionExcluded"]).friendlyString}") + } + + if (predicates.isEmpty()) predicates.add("*") + + return predicates.join(" ") +} + def getSubprojectVersion(Project project) { def version @@ -122,7 +148,21 @@ def static setupRepositories(RepositoryHandler repositories) { } } -def moduleDependencies(Project project, List depNames) { +def moduleDependencies(Project project, List projectNames) { + def depNames = [] + + def projectMCVersion = VersionHelper.parseVersion(getMCVersion(project)) + + rootProject.subprojects { + def subProjectName = getProjectSimpleName(it) + + if (projectNames.contains(subProjectName)) { + def predicate = VersionHelper.parsePredicate(getMCRange(it)) + + if (predicate.test(projectMCVersion)) depNames.add(it.name) + } + } + if (!project.name.endsWith("_common")) { def commonProject = findProject(":${getProjectSimpleName(project)}_common") @@ -173,30 +213,6 @@ def moduleDependencies(Project project, List depNames) { } } -static def getMCRange(Project project) { - def predicates = [] - - if (project.hasProperty("minVersionIncluded")) { - predicates.add(">=${VersionHelper.parseVersion(project["minVersionIncluded"]).friendlyString}") - } - - if (project.hasProperty("minVersionExcluded")) { - predicates.add(">${VersionHelper.parseVersion(project["minVersionExcluded"]).friendlyString}") - } - - if (project.hasProperty("maxVersionIncluded")) { - predicates.add("<=${VersionHelper.parseVersion(project["maxVersionIncluded"]).friendlyString}") - } - - if (project.hasProperty("maxVersionExcluded")) { - predicates.add("<${VersionHelper.parseVersion(project["maxVersionExcluded"]).friendlyString}") - } - - if (predicates.isEmpty()) predicates.add("*") - - return predicates.join(" ") -} - allprojects { group = "net.legacyfabric.legacy-fabric-api"