Skip to content

Commit

Permalink
Adopt convention plugin (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-nenashev authored Dec 11, 2023
1 parent 9128137 commit b5bc65e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 248 deletions.
255 changes: 7 additions & 248 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,28 @@ buildscript {
}

plugins {
id 'java'
id 'java-library'
id 'idea'
id 'signing'
id 'maven-publish'
id 'jacoco'
id 'com.diffplug.spotless' version '6.22.0'
id 'com.palantir.git-version' version '3.0.0'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'io.github.gradle-nexus.publish-plugin' version "1.3.0"
}

wrapper {
gradleVersion = '8.2.1'
distributionType = Wrapper.DistributionType.BIN
id 'org.wiremock.tools.gradle.wiremock-extension-convention' version '0.1.2'
}

group 'org.wiremock.extensions'
project.ext {
baseArtifact = 'wiremock-state-extension'
versions = [
wiremock : '3.3.1',
caffeine : '3.1.8',
handlebars: '4.3.1',
junit : '5.10.1',
assertj : '3.24.2',
restAssured: '5.4.0',
awaitility: '4.2.0'
]
}

project.archivesBaseName = "${baseArtifact}"
configurations {
standaloneOnly
}

java {
withSourcesJar()
withJavadocJar()
}

jar {
archiveBaseName.set("${baseArtifact}")
exclude 'META-INF/services'
dependencies {
implementation("com.github.ben-manes.caffeine:caffeine:${versions.caffeine}")
implementation("com.github.jknack:handlebars-helpers:${versions.handlebars}") {
exclude group: 'org.mozilla', module: 'rhino'
}
}

shadowJar {
archiveBaseName.set("${baseArtifact}-standalone")
archiveClassifier.set('')
configurations = [
project.configurations.runtimeClasspath,
project.configurations.standaloneOnly
]

with copySpec {
from("shadowjar/resources") {}
}

relocate "com.github.ben-manes.caffeine", 'wiremock.com.github.ben-manes.caffeine'
relocate "com.github.jknack", 'wiremock.com.github.jknack'


dependencies {
exclude(dependency('junit:junit'))
}

mergeServiceFiles()

exclude 'META-INF/maven/**'
exclude 'module-info.class'
exclude 'handlebars-*.js'
}

test {
Expand All @@ -88,196 +40,3 @@ jacocoTestReport {
html.required = true
}
}

group 'org.wiremock.extensions'

version gitVersion()

signing {
// Docs: https://github.com/wiremock/community/blob/main/infra/maven-central.md
required {
!version.toString().contains("SNAPSHOT") && (gradle.taskGraph.hasTask("uploadArchives") || gradle.taskGraph.hasTask("publish"))
}
def signingKey = providers.environmentVariable("OSSRH_GPG_SECRET_KEY").orElse("").get()
def signingPassphrase = providers.environmentVariable("OSSRH_GPG_SECRET_KEY_PASSWORD").orElse("").get()
if (!signingKey.isEmpty() && !signingPassphrase.isEmpty()) {
useInMemoryPgpKeys(signingKey, signingPassphrase)
sign(publishing.publications)
}
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/wiremock/wiremock-state-extension"
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}

getComponents().withType(AdhocComponentWithVariants).each { c ->
c.withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
skip()
}
}

publications {
mavenJava(MavenPublication) {
artifactId = "${baseArtifact}"

from components.java

pom {
name = "${baseArtifact}"
description = 'A WireMock extension to transfer state in between stubs'
url = 'https://github.com/wiremock/wiremock-state-extension'


scm {
connection = 'https://github.com/wiremock/wiremock-state-extension.git'
developerConnection = 'https://github.com/wiremock/wiremock-state-extension.git'
url = 'https://github.com/wiremock/wiremock-state-extension.git'
}

licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}

developers {
developer {
id = 'dirkbolte'
name = 'Dirk Bolte'
email = '[email protected]'
}
}
}
}
standaloneJar(MavenPublication) { publication ->
artifactId = "${baseArtifact}-standalone"

project.shadow.component(publication)

artifact sourcesJar
artifact javadocJar

pom {

name = "${baseArtifact}-standalone"
description = 'A WireMock extension to transfer state in between stubs - to be used with WireMock standalone'
url = 'https://github.com/wiremock/wiremock-state-extension'


scm {
connection = 'https://github.com/wiremock/wiremock-state-extension.git'
developerConnection = 'https://github.com/wiremock/wiremock-state-extension.git'
url = 'https://github.com/wiremock/wiremock-state-extension.git'
}

licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}

developers {
developer {
id = 'dirkbolte'
name = 'Dirk Bolte'
email = '[email protected]'
}
}
}
}
}
}

task checkReleasePreconditions {
doLast {
def REQUIRED_GIT_BRANCH = 'HEAD'
def currentGitBranch = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim()
assert currentGitBranch == REQUIRED_GIT_BRANCH, "Must be on the $REQUIRED_GIT_BRANCH branch in order to release to Sonatype"
}
}
publish.dependsOn checkReleasePreconditions
publish.dependsOn 'signStandaloneJarPublication'
publish.dependsOn 'signMavenJavaPublication'

// FIXME: remove after https://github.com/gradle/gradle/issues/26091
tasks.withType(AbstractPublishToMaven).configureEach {
def signingTasks = tasks.withType(Sign)
mustRunAfter(signingTasks)
}

repositories {
mavenCentral()
mavenLocal()
}

dependencies {
implementation("org.wiremock:wiremock:${versions.wiremock}")
implementation("com.github.ben-manes.caffeine:caffeine:${versions.caffeine}")
implementation("com.github.jknack:handlebars-helpers:${versions.handlebars}") {
exclude group: 'org.mozilla', module: 'rhino'
}

testImplementation(platform("org.junit:junit-bom:${versions.junit}"))
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation("org.assertj:assertj-core:${versions.assertj}")
testImplementation(platform("io.rest-assured:rest-assured-bom:${versions.restAssured}"))
testImplementation("io.rest-assured:rest-assured")
testImplementation("org.awaitility:awaitility:${versions.awaitility}")
}


sourceCompatibility = 11
targetCompatibility = 11

compileJava {
options.encoding = 'UTF-8'
}

compileTestJava {
options.encoding = 'UTF-8'
}
assemble.dependsOn jar, shadowJar

test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}

idea {
project {
jdkName = '11'
languageLevel = '11'
}
}

nexusPublishing {
// See https://github.com/wiremock/community/blob/main/infra/maven-central.md
repositories {
sonatype {
// TODO: allow configuring destinations for oss1
// nexusUrl.set(uri("https://oss.sonatype.org/service/local/"))
// snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/"))
def envUsername = providers.environmentVariable("OSSRH_USERNAME").orElse("").get()
def envPassword = providers.environmentVariable("OSSRH_TOKEN").orElse("").get()
if (!envUsername.isEmpty() && !envPassword.isEmpty()) {
username.set(envUsername)
password.set(envPassword)
}
}
}
}

7 changes: 7 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
baseArtifact = wiremock-state-extension
version = 0.6.0-SNAPSHOT
description = A WireMock extension to transfer state in between stubs
githubRepo = wiremock-state-extension
developer.id=dirkbolte
developer.name=Dirk Bolte
developer.email[email protected]

0 comments on commit b5bc65e

Please sign in to comment.