neoforged / ModDevGradle

A Gradle plugin for developing Minecraft mods using NeoForge
https://projects.neoforged.net/neoforged/moddevgradle
GNU Lesser General Public License v2.1
25 stars 6 forks source link

Jar-in-Jar: Docs and example #33

Closed shartte closed 2 months ago

shartte commented 2 months ago

Jar-in-Jar

To embed external Jar-files into your mod file, you can use the jarjar configuration added by the plugin.

Subprojects

For example, if you have a coremod in a subproject and want to embed its jar file, you can use the following syntax.

dependencies {
    jarJar project(":coremod")
}

When another mod also has a coremod subproject, Jar-in-Jar will use the group set in both projects to decide whether they conflict or not. The filename will also be automatically prefixed with your group to avoid Java module-name conflicts.

External Dependencies

When you want to bundle external dependencies, Jar-in-Jar has to be able to select a single copy of that dependency when it is bundled by multiple mods (possibly even in different versions). To support this scenario, you should set a supported version range to avoid mod incompatibilities.

dependencies {
    jarJar(implementation("org.commonmark:commonmark")) {
      version {
        // The version range your mod is actually compatible with. 
        // Note that you may receive a *lower* version than your preferred if another
        // Mod is only compatible up to 1.7.24, for example, your mod might get 1.7.24 at runtime.
        strictly '[0.1, 1.0)'
        prefer '0.21.0' // The version actually used in your dev workspace
      }
    }
}

Version ranges use the Maven version range format:

Range Meaning
(,1.0] x <= 1.0
1.0 Soft requirement on 1.0. It allows for any version.
[1.0] Hard requirement on 1.0
[1.2,1.3] 1.2 <= x <= 1.3
[1.0,2.0) 1.0 <= x < 2.0
[1.5,) x >= 1.5
(,1.0],[1.2,) x <= 1.0 or x >= 1.2. Multiple sets are comma-separated
(,1.1),(1.1,) This excludes 1.1 if it is known not to work in combination with this library
neoforged-pr-publishing[bot] commented 2 months ago

Last commit published: 50920ef7a82c8fa5a1c7cb1c6ee014aa94f0ea15.

PR Publishing ### The artifacts published by this PR: - :package: [`net.neoforged.moddev:net.neoforged.moddev.gradle.plugin:0.1.94-pr-33-jij-docs-and-example`](https://github.com/neoforged/ModDevGradle/packages/2179884) - :package: [`net.neoforged:moddev-gradle:0.1.94-pr-33-jij-docs-and-example`](https://github.com/neoforged/ModDevGradle/packages/2179883) - :package: [`net.neoforged.moddev.repositories:net.neoforged.moddev.repositories.gradle.plugin:0.1.94-pr-33-jij-docs-and-example`](https://github.com/neoforged/ModDevGradle/packages/2179885) ### Repository Declaration In order to use the artifacts published by the PR, add the following repository to your buildscript: ```gradle repositories { maven { name 'Maven for PR #33' // https://github.com/neoforged/ModDevGradle/pull/33 url 'https://prmaven.neoforged.net/ModDevGradle/pr33' content { includeModule('net.neoforged.moddev', 'net.neoforged.moddev.gradle.plugin') includeModule('net.neoforged', 'moddev-gradle') includeModule('net.neoforged.moddev.repositories', 'net.neoforged.moddev.repositories.gradle.plugin') } } } ```