Add your SDK key
Without a key, your mod runs normally with reporting off, and the log says No SDK key found, reporting is off.
Bundle it in your jar
Nitea reads nitea/<modid>.properties from your mod's resources:
sdkKey=nt_your_sdk_key
The file is packed into your jar when you build, so released versions report with no extra setup. Keep it out of your repository:
src/main/resources/nitea/*.properties
Recommended: generate it from .env
Instead of a resource file, keep the key in a git-ignored .env and let Gradle write the properties file at build time. This is what the example mod does.
- .env
- build.gradle
- .gitignore
NITEA_SDK_KEY=nt_your_sdk_key
var generateNiteaConfig = tasks.register("generateNiteaConfig") {
var envText = providers.fileContents(layout.projectDirectory.file(".env")).asText.orElse("")
var outputDir = layout.buildDirectory.dir("generated/sources/niteaConfig")
var modId = mod_id
inputs.property("env", envText)
outputs.dir(outputDir)
doLast {
var env = [:]
envText.get().eachLine { String line ->
line = line.trim()
if (!line || line.startsWith('#') || !line.contains('=')) return
var parts = line.split('=', 2)
env[parts[0].trim()] = parts[1].trim().replaceAll(/^["']|["']$/, '')
}
var props = new Properties()
if (env.NITEA_SDK_KEY) props.setProperty('sdkKey', env.NITEA_SDK_KEY)
var file = outputDir.get().file("nitea/${modId}.properties").asFile
file.parentFile.mkdirs()
file.withWriter('UTF-8') { props.store(it, ' Generated from .env. Do not commit.') }
}
}
sourceSets.main.resources.srcDir generateNiteaConfig
.env
Other ways to set the key
Nitea uses the first key it finds, in this order:
| Source | Example |
|---|---|
| Builder | .sdkKey("nt_...") |
| JVM system property | -Dnitea.examplemod.sdkKey=nt_... |
| Environment variable | NITEA_EXAMPLEMOD_SDK_KEY=nt_... |
| Bundled resource | nitea/examplemod.properties containing sdkKey=nt_... |
The system property and environment variable are handy on a test server, where you don't want the key in a file.
Is it safe to ship the key?
Yes. The key can only send events to your project; it can't read or change anything. Like any client-side key, anyone can extract it from a released jar, so keep it out of your repository and regenerate it if it's ever abused.
If the Nitea API rejects the key, Nitea logs a warning and stays off until the next launch.