Skip to content
zml edited this page Oct 13, 2021 · 4 revisions

A basic setup is straightforward:

  1. Add the VanillaGradle plugin to your project
  2. Declare a dependency on Minecraft
  3. Add any desired run configurations or access wideners in the minecraft extension
  4. If sources are desired, run the decompile task to prepare sources.

Example:

plugins {
    `java-library`
    id("org.spongepowered.gradle.vanilla") version "0.2"
}

minecraft {
    version("1.16.5")
    // or: injectedVersion("path to json file")
    // or: latestRelease()
    // or: latestSnapshot()

    platform(org.spongepowered.gradle.vanilla.repository.MinecraftPlatform.JOINED)

    runs {
        // VanillaGradle provides two presets, for a Minecraft client and server
        // These settings gather information based on the Mojang launcher manifest
        client()
        server()

        // A customized run configuration
        server("integrationTestServer") {
            mainClass("org.example.test.IntegrationTestMain")
        }
    }

     // optional
    // accessWideners("src/main/resources/myproject.accesswidener")
}

This prepares a workspace with Minecraft on the classpath, that will run a Vanilla client or server depending on the run configuration selected. For modding, customization will be needed depending on the project at hand. See DSL Reference for a complete listing of options available.

Multiproject builds

Multiproject builds need some extra care because VanillaGradle's synthesized repository needs to be added to not just the producer project, but any consumer projects within the same build. The easiest way to do this is with central repository declaration. When that is not possible, the alternative is to add VanillaGradle as a plugin to every build that uses it.

Using central repository declaration (Gradle 6.8+)

In Gradle 6.8+, repositories can be declared in the settings.gradle. This is the preferred way to handle multi-project builds where possible. To be compatible with this feature, VanillaGradle can be applied as a settings plugin, which will cause the necessary repositories to be exposed to every project.

The plugin ID is the same, but minimal configuration is available within the settings file.

Simply:

plugins {
    id("org.spongepowered.gradle.vanilla") version "0.2"
    // ... anything else ...
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    // repositories declared
}

}

Supported Gradle properties

There are some aspects of VanillaGradle that can be configured through Gradle properties. These are not necessarily exposed in any other way, due to how they're referenced in the initialization cycle.

These can be provided through any mechanism that Gradle supports to specify properties before the buildscript is evaluated, including the per-user gradle.properties file.

  • (since 0.2.1) org.spongepowered.gradle.vanilla.sharedCacheRoot: A path to the global shared cache directory, to use instead of its default location at ~/.gradle/caches/VanillaGradle/
  • (since 0.2.1) org.spongepowered.gradle.vanilla.projectCacheRoot: A path to the project-specific cache directory, to use instead of its default location at <rootProject>/.gradle/caches/VanillaGradle/
Clone this wiki locally