Skip to content

Commit

Permalink
Publish a platform (BOM) with the Minecraft dependencies (#6)
Browse files Browse the repository at this point in the history
This platform contains all libraries between the server and the client but prefers using the lower version when they have different versions.
  • Loading branch information
Matyrobbrt authored Jan 18, 2025
1 parent 9fe841d commit b002e2c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- 1.19.2
- 1.20.1
- 1.21.1
- 1.21.4

runs-on: ubuntu-latest
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.neoforged.minecraftdependencies

import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.apache.maven.artifact.versioning.ComparableVersion
import org.gradle.api.DefaultTask
Expand Down Expand Up @@ -100,6 +101,7 @@ abstract class GenerateModuleMetadata extends DefaultTask implements HasMinecraf
variants.add([
name : 'clientCompileDependencies',
attributes : [
'org.gradle.category' : 'library',
'org.gradle.usage' : 'java-api',
'org.gradle.jvm.version' : javaVersion,
'net.neoforged.distribution': 'client'
Expand All @@ -114,6 +116,7 @@ abstract class GenerateModuleMetadata extends DefaultTask implements HasMinecraf
variants.add([
name : 'clientRuntimeDependencies',
attributes : [
'org.gradle.category' : 'library',
'org.gradle.usage' : 'java-runtime',
'org.gradle.jvm.version' : javaVersion,
'net.neoforged.distribution': 'client'
Expand All @@ -128,6 +131,7 @@ abstract class GenerateModuleMetadata extends DefaultTask implements HasMinecraf
variants.add([
name : 'serverCompileDependencies',
attributes : [
'org.gradle.category' : 'library',
'org.gradle.usage' : 'java-api',
'org.gradle.jvm.version' : javaVersion,
'net.neoforged.distribution': 'server'
Expand All @@ -142,6 +146,7 @@ abstract class GenerateModuleMetadata extends DefaultTask implements HasMinecraf
variants.add([
name : 'serverRuntimeDependencies',
attributes : [
'org.gradle.category' : 'library',
'org.gradle.usage' : 'java-runtime',
'org.gradle.jvm.version' : javaVersion,
'net.neoforged.distribution': 'server'
Expand All @@ -154,11 +159,30 @@ abstract class GenerateModuleMetadata extends DefaultTask implements HasMinecraf
]]
])

variants.add([
name : 'platformDependencies',
attributes : [
'org.gradle.usage' : 'java-api',
'org.gradle.category' : 'platform'
],
dependencyConstraints: commonDeps(clientDepEntries, serverDepEntries)
])

variants.add([
name : 'platformRuntimeDependencies',
attributes : [
'org.gradle.usage' : 'java-runtime',
'org.gradle.category' : 'platform'
],
dependencyConstraints: commonDeps(clientDepEntriesForRuntime, serverDepEntries)
])

platforms.each { os ->
List<String> nativeList = clientNatives.get(os) ?: []
variants.add([
name : 'client' + os.capitalize() + 'Natives',
attributes : [
'org.gradle.category' : 'library',
'org.gradle.usage' : 'java-runtime',
'org.gradle.jvm.version' : javaVersion,
'net.neoforged.distribution' : 'client',
Expand Down Expand Up @@ -374,6 +398,24 @@ abstract class GenerateModuleMetadata extends DefaultTask implements HasMinecraf
}
}

@CompileDynamic
private static Collection commonDeps(List... lists) {
Map<String, Map> highestVersion = [:]
for (var list : lists) {
list.forEach { Map item ->
var id = item.group + ':' + item.module
highestVersion.merge(id, item) { oldValue, newValue ->
// Prefer lowest version
if ((new ComparableVersion(oldValue.version.strictly) < new ComparableVersion(oldValue.version.strictly))) {
return oldValue
}
return newValue
}
}
}
return highestVersion.values()
}

private static List depsOf(List<String> deps) {
return deps.unique(false).collect { depOf(it) }
}
Expand Down

0 comments on commit b002e2c

Please sign in to comment.