This PowerShell script automates the process of deploying a Minecraft plugin to a remote Crafty server. It performs the following steps:
- Detects the path to Gradle if not specified.
- Updates the version number in the
build.gradle
file. - Builds the project using Gradle.
- Cleans up old plugin files on the remote server.
- Deploys the newly built plugin to the remote server.
- Restarts the Minecraft server (optional, if added).
- Gradle: Ensure Gradle is installed on your system. The script can auto-detect Gradle if it's in your system's PATH.
- PowerShell: This script is designed to run in PowerShell.
- SSH Access: SSH must be configured properly for communication with the remote server. You need to provide SSH credentials during script execution.
Before running the script, ensure the following configuration parameters are correctly set:
gradlePath
: The path to thegradle.bat
file. If not provided, the script will attempt to auto-detect it.projectDir
: The path to your project's root directory.buildGradlePath
: The path to yourbuild.gradle
file.sshUser
: SSH username for the remote server.sshServer
: The hostname or IP address of the remote server.remoteCraftyServerPath
: The base path on the remote server where Crafty is installed.remoteServerId
: The unique identifier for your Minecraft server on the remote Crafty server.buildLibsPath
: The path to the directory where Gradle outputs the built JAR files.
build/libs
Folder: This folder will be cleared before deploying new builds. Ensure no important files are left in this directory before running the script.plugins
Folder: Theplugins
folder on the remote server will be cleared before deploying new files. Ensure no important plugins are lost.- Versioning: Make sure to manually update the patch version in the
build.gradle
file before running the script. The script only increments the patch version automatically. - SSH Credentials: The script will prompt for the SSH password twice:
- During the cleanup of old files.
- During the deployment of new files.
-
Prepare the Script: Save the script as
Deploy-Plugin.ps1
on your local machine. -
Run the Script:
powershell -ExecutionPolicy Bypass -File "Deploy-Plugin.ps1" -gradlePath "path\to\gradle.bat" -projectDir "path\to\project" -buildGradlePath "path\to\build.gradle" -sshUser "sshUser" -sshServer "sshServer" -remoteCraftyServerPath "/opt/docker/crafty/servers" -remoteServerId "remoteServerId" -buildLibsPath "path\to\build\libs"
-
Script Execution:
- The script will first attempt to auto-detect the Gradle path if not specified.
- It will then update the version in the
build.gradle
file and build the project. - Old plugin files on the remote server will be cleared.
- The newly built JAR file will be deployed to the remote server.
- The script will then prompt you for the SSH password.
If the gradlePath
is not provided, the script will attempt to detect it automatically using the system’s PATH.
The script updates the version in build.gradle
by incrementing the patch version number. Ensure that your versioning format is consistent.
The script executes Gradle build commands from the project directory.
The Establish-SSHConnection
function sets up the SSH connection and adds the server to known hosts if not already present.
The Cleanup-OldFiles
function removes old plugin files from the remote server. It uses SSH to execute commands on the remote server.
The Deploy-NewFiles
function uploads the newly built JAR file to the remote server using SCP. You will be prompted to enter your SSH password.
Restart the server manually, you might stop it before starting the script and start it after its done.
- Gradle Not Found: Ensure Gradle is installed and available in the system PATH. Provide the correct path to
gradle.bat
if auto-detection fails. - SSH Connection Issues: Verify SSH credentials and network connectivity to the remote server.
For further assistance, consult the Gradle and SSH documentation or seek help from your system administrator.