听风逝夜

This is a comprehensive documentation for the dev.coolrequest.gosync Gradle plugin.


dev.coolrequest.gosync Gradle Plugin Documentation

Overview

dev.coolrequest.gosync is a highly efficient deployment plugin for Gradle. It streamlines the process of transferring your application JAR and its dependencies to a remote server immediately after the build process.

Unlike traditional upload tools, goSync performs an MD5 checksum comparison between local files and remote files. It only uploads files that have changed, significantly reducing deployment time and bandwidth usage. It natively supports both standard SSH connections and JumpServer (Bastion Host) environments.


Key Features


Configuration

Add the following block to your build.gradle file to configure the plugin:

goSync {
    // Connection Settings
    serverType = "jumpserver" // Options: "jumpserver" or "simple"
    serverAddress = "192.168.1.100"
    port = 2222
    userName = "your_username"
    userPass = "your_password"

    // JumpServer Specific
    afterConnectedCommand = "p\r25\r2\r"

    // Remote Paths
    libDirectory = "/your-libs"
    mainJarDirectory = "/your-jar"
}

Parameter Details

Parameter Type Required Description
serverType String Yes Defines the connection mode.
simple: Standard SSH connection.
jumpserver: Connects via a Bastion host that requires navigation commands.
serverAddress String Yes The IP address or domain name of the JumpServer or the destination host.
port Integer Yes The SSH port. Typically 22 for standard SSH or 2222 for JumpServer.
userName String Yes Username for authentication.
userPass String Yes Password for authentication.
afterConnectedCommand String No Specific to JumpServer. A string representing the keyboard inputs needed to reach the destination machine. Use \r to represent the “Enter” key.
Example: p\r25\r (Search ‘p’, then select item 25).
libDirectory String Yes The absolute path on the remote server where the project’s dependency libraries (.jar files) should be stored.
mainJarDirectory String Yes The absolute path on the remote server where the project’s primary output JAR should be stored.

How It Works

  1. Post-Build Execution: The plugin automatically triggers after the Gradle jar task (or the specific task producing the output).
  2. Dependency Extraction: It identifies all runtime dependencies of the project.
  3. MD5 Verification:
    • The plugin calculates the MD5 hash of the local main.jar and all dependency JARs.
    • It checks the MD5 of the corresponding files on the remote server.
  4. Selective Upload:
    • If a file does not exist on the remote server, it is uploaded.
    • If a file exists but the MD5 differs, it is overwritten.
    • If the MD5 matches, the file is skipped to save time.
  5. JumpServer Navigation: If serverType is set to jumpserver, the plugin opens an interactive session and “types” the afterConnectedCommand automatically to tunnel through to the internal server before initiating the SFTP transfer.

Usage Example

To run the sync manually, you can execute:

./gradlew goSync

Or, if configured as part of the build pipeline, it will run automatically when you build the project:

Author: coolrequest
Plugin ID: dev.coolrequest.gosync