-
Notifications
You must be signed in to change notification settings - Fork 0
getting started
github-actions[bot] edited this page Aug 6, 2026
·
1 revision
This guide will help you get up and running with YamlAnnotations quickly.
plugins {
id 'com.gradleup.shadow'
}
repositories {
maven { url 'https://repo.codemc.io/repository/avarionmc/' }
}
dependencies {
implementation 'org.avarion:yaml:VERSION'
}
jar {
dependsOn shadowJar
}<repositories>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.io/repository/avarionmc/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.avarion</groupId>
<artifactId>yaml</artifactId>
<version>VERSION</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>Replace VERSION with the latest version from CodeMC.
- Java 17 or higher (required for Record support)
- SnakeYAML 1.x or 2.x (automatically selected at runtime)
Create a class that extends YamlFileInterface and annotate your fields:
import org.avarion.yaml.YamlFileInterface;
import org.avarion.yaml.YamlKey;
public class MyConfig extends YamlFileInterface {
@YamlKey("server.name")
public String serverName = "My Server";
@YamlKey("server.port")
public int port = 25565;
@YamlKey("server.motd")
public String motd = "Welcome!";
}// Load configuration (creates file with defaults if it doesn't exist)
MyConfig config = new MyConfig().load("config.yml");
// Access values
System.out.println("Server: " + config.serverName);
System.out.println("Port: " + config.port);
// Modify and save
config.serverName = "Updated Server";
config.save("config.yml");server:
name: My Server
port: 25565
motd: Welcome!Use @YamlComment to add documentation to your configuration:
import org.avarion.yaml.YamlComment;
import org.avarion.yaml.YamlKey;
public class MyConfig extends YamlFileInterface {
@YamlComment("The display name of your server")
@YamlKey("server.name")
public String serverName = "My Server";
@YamlComment("Port number (1-65535)")
@YamlKey("server.port")
public int port = 25565;
}Output:
server:
# The display name of your server
name: My Server
# Port number (1-65535)
port: 25565Use the @YamlFile annotation to add a header comment:
import org.avarion.yaml.YamlFile;
import org.avarion.yaml.YamlFileInterface;
import org.avarion.yaml.YamlKey;
@YamlFile(header = """
Server Configuration File
Edit values below to customize your server.
""")
public class MyConfig extends YamlFileInterface {
@YamlKey("server.name")
public String serverName = "My Server";
}Output:
# Server Configuration File
# Edit values below to customize your server.
server:
name: My ServerFor Minecraft plugins, you can load/save using the plugin instance:
@YamlFile(fileName = "config.yml")
public class PluginConfig extends YamlFileInterface {
@YamlKey("settings.debug")
public boolean debug = false;
}
// In your plugin's onEnable():
PluginConfig config = new PluginConfig().load(this); // Uses plugin's data folder
config.save(this);- Supported Types - Learn about all supported data types
- Annotations Reference - Detailed annotation documentation
- Working with Records - Use Java Records for complex types
- Advanced Usage - Custom processors and advanced features