wiremock / gradle-wiremock-extension-plugins

Gradle plugins that bundles common packaging and release logic for WireMock extensions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gradle Convention plugin for WireMock Extensions

This convention plugin helps to Build WireMock extensions so that they can be hosted on Maven Central and released automatically from GitHub actions. See the Maven Central Publishing documentation to learn more.

Features:

  • Code signing and POM generation for Maven Central publishing
  • Proper shading of artifacts (work in progress)

Requirements

  • Gradle 8.x
  • Java 11 or 17

Usage

Basic use

Set the following gradle.properties:

baseArtifact = my-test-wiremock-extension
version = 1.0.0-SNAPSHOT
description = My Test WireMock Extension
githubRepo = wiremock-my-test-extension
developer.id=todo
developer.name=TODO WireMock Developer
developer.email=noreply@wiremock.org

Use the plugin in your build.gradle.kts file:

buildscript {
    repositories {
        mavenCentral()
    }
}
        
plugins {
    kotlin("jvm") version "$embeddedKotlinVersion"
    id("org.wiremock.tools.gradle.wiremock-extension-convention")
}

Or in Gradle:

buildscript {
    repositories {
        mavenCentral()
    }
}

plugins {
    id 'org.wiremock.tools.gradle.wiremock-extension-convention' version '0.1.2'
}

Shading of dependencies

When you need to include additional dependencies, they should be shaded in the shadedJar task:

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
                
dependencies {
    implementation("com.github.ben-manes.caffeine:caffeine:3.1.8")
}

tasks {
    named<ShadowJar>("shadowJar") {
        relocate("com.github.ben-manes.caffeine", "wiremock.com.github.ben-manes.caffeine")
        relocate("com.github.jknack", "wiremock.com.github.jknack")
    }
}

Release Automation

To automate releases with this extension, add the following GitHub action in .github/workflows/:

name: Release
on:
  release:
    types: [published]

jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v3
      - name: Set up Java
        uses: actions/setup-java@v3
        with:
          java-version: '11'
          distribution: 'adopt'
      - name: Validate Gradle wrapper
        uses: gradle/wrapper-validation-action@v1

      - name: Determine new version
        id: new_version
        run: |
          NEW_VERSION=$(echo "${GITHUB_REF}" | cut -d "/" -f3)
          echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT

      - name: Publish package
        id: publish_package
        uses: gradle/gradle-build-action@v2.9.0
        with:
          arguments: -Pversion=${{ steps.new_version.outputs.new_version }} publish closeAndReleaseStagingRepository
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
          OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
          OSSRH_GPG_SECRET_KEY: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
          OSSRH_GPG_SECRET_KEY_PASSWORD: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}

Once the request for Maven Central Publishing authorization is completed, you can trigger the release Pipeline by just publishing a GitHub Release. Consider also configuring Release Drafter to automate chaangelogs.

Usage Examples

About

Gradle plugins that bundles common packaging and release logic for WireMock extensions

License:Apache License 2.0


Languages

Language:Kotlin 100.0%