# Builds a mod jar from source. # # build-mod.ps1 [-Source ] [-Output ] # # Mods are ordinary jars with a descriptor at META-INF/rsxmod.properties. There # is no annotation processor and no gradle: javac against the loader jar, then # jar, then done. param( [string]$Source = 'G:\RustNotMC\rsx-mods\rsxm-demo', [string]$Output = '' ) $ErrorActionPreference = 'Stop' if (-not $Output) { $Output = Join-Path $Source 'dist' } $Loader = 'G:\RustNotMC\rsx-client\dist\rsx-loader.jar' if (-not (Test-Path $Loader)) { throw "loader jar missing: $Loader" } $Name = Split-Path -Leaf $Source $build = Join-Path $Source 'build' $classes = Join-Path $build 'classes' $jarPath = Join-Path $Output "$Name.jar" Remove-Item $classes -Recurse -Force -ErrorAction SilentlyContinue New-Item -ItemType Directory -Force -Path $classes | Out-Null $mainSrc = Join-Path $Source 'src\main\java' $mainRes = Join-Path $Source 'resources' $mainFiles = @(Get-ChildItem $mainSrc -Recurse -Filter '*.java' | ForEach-Object { $_.FullName }) Write-Host " sources: $($mainFiles.Count)" & javac -encoding UTF-8 -nowarn -proc:none --release 17 -cp $Loader -d $classes @mainFiles if ($LASTEXITCODE -ne 0) { throw "javac failed" } if (Test-Path $mainRes) { Copy-Item -Recurse -Force (Join-Path $mainRes '*') $classes } New-Item -ItemType Directory -Force -Path $Output | Out-Null Remove-Item $jarPath -Force -ErrorAction SilentlyContinue # a mod is a library, never an executable, so there is no main class here Push-Location $classes & jar --create --file $jarPath -C $classes . $jarExit = $LASTEXITCODE Pop-Location if ($jarExit -ne 0) { throw "jar failed with exit code $jarExit" } Write-Host '' Write-Host " $jarPath ($((Get-Item $jarPath).Length) bytes)" exit 0