Skip to content

Commit b5bc65e

Browse files
Adopt convention plugin (#108)
Uses https://github.com/wiremock/gradle-wiremock-extension-plugins to simplify the configuration
1 parent 9128137 commit b5bc65e

File tree

2 files changed

+14
-248
lines changed

2 files changed

+14
-248
lines changed

build.gradle

Lines changed: 7 additions & 248 deletions
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,28 @@ buildscript {
55
}
66

77
plugins {
8-
id 'java'
9-
id 'java-library'
10-
id 'idea'
11-
id 'signing'
12-
id 'maven-publish'
138
id 'jacoco'
149
id 'com.diffplug.spotless' version '6.22.0'
15-
id 'com.palantir.git-version' version '3.0.0'
16-
id 'com.github.johnrengelman.shadow' version '8.1.1'
17-
id 'io.github.gradle-nexus.publish-plugin' version "1.3.0"
18-
}
19-
20-
wrapper {
21-
gradleVersion = '8.2.1'
22-
distributionType = Wrapper.DistributionType.BIN
10+
id 'org.wiremock.tools.gradle.wiremock-extension-convention' version '0.1.2'
2311
}
2412

13+
group 'org.wiremock.extensions'
2514
project.ext {
26-
baseArtifact = 'wiremock-state-extension'
2715
versions = [
28-
wiremock : '3.3.1',
2916
caffeine : '3.1.8',
30-
handlebars: '4.3.1',
31-
junit : '5.10.1',
32-
assertj : '3.24.2',
33-
restAssured: '5.4.0',
34-
awaitility: '4.2.0'
3517
]
3618
}
3719

38-
project.archivesBaseName = "${baseArtifact}"
39-
configurations {
40-
standaloneOnly
41-
}
42-
43-
java {
44-
withSourcesJar()
45-
withJavadocJar()
46-
}
47-
48-
jar {
49-
archiveBaseName.set("${baseArtifact}")
50-
exclude 'META-INF/services'
20+
dependencies {
21+
implementation("com.github.ben-manes.caffeine:caffeine:${versions.caffeine}")
22+
implementation("com.github.jknack:handlebars-helpers:${versions.handlebars}") {
23+
exclude group: 'org.mozilla', module: 'rhino'
24+
}
5125
}
5226

5327
shadowJar {
54-
archiveBaseName.set("${baseArtifact}-standalone")
55-
archiveClassifier.set('')
56-
configurations = [
57-
project.configurations.runtimeClasspath,
58-
project.configurations.standaloneOnly
59-
]
60-
61-
with copySpec {
62-
from("shadowjar/resources") {}
63-
}
64-
6528
relocate "com.github.ben-manes.caffeine", 'wiremock.com.github.ben-manes.caffeine'
6629
relocate "com.github.jknack", 'wiremock.com.github.jknack'
67-
68-
69-
dependencies {
70-
exclude(dependency('junit:junit'))
71-
}
72-
73-
mergeServiceFiles()
74-
75-
exclude 'META-INF/maven/**'
76-
exclude 'module-info.class'
77-
exclude 'handlebars-*.js'
7830
}
7931

8032
test {
@@ -88,196 +40,3 @@ jacocoTestReport {
8840
html.required = true
8941
}
9042
}
91-
92-
group 'org.wiremock.extensions'
93-
94-
version gitVersion()
95-
96-
signing {
97-
// Docs: https://github.com/wiremock/community/blob/main/infra/maven-central.md
98-
required {
99-
!version.toString().contains("SNAPSHOT") && (gradle.taskGraph.hasTask("uploadArchives") || gradle.taskGraph.hasTask("publish"))
100-
}
101-
def signingKey = providers.environmentVariable("OSSRH_GPG_SECRET_KEY").orElse("").get()
102-
def signingPassphrase = providers.environmentVariable("OSSRH_GPG_SECRET_KEY_PASSWORD").orElse("").get()
103-
if (!signingKey.isEmpty() && !signingPassphrase.isEmpty()) {
104-
useInMemoryPgpKeys(signingKey, signingPassphrase)
105-
sign(publishing.publications)
106-
}
107-
}
108-
109-
publishing {
110-
repositories {
111-
maven {
112-
name = "GitHubPackages"
113-
url = "https://maven.pkg.github.com/wiremock/wiremock-state-extension"
114-
credentials {
115-
username = System.getenv("GITHUB_ACTOR")
116-
password = System.getenv("GITHUB_TOKEN")
117-
}
118-
}
119-
}
120-
121-
getComponents().withType(AdhocComponentWithVariants).each { c ->
122-
c.withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
123-
skip()
124-
}
125-
}
126-
127-
publications {
128-
mavenJava(MavenPublication) {
129-
artifactId = "${baseArtifact}"
130-
131-
from components.java
132-
133-
pom {
134-
name = "${baseArtifact}"
135-
description = 'A WireMock extension to transfer state in between stubs'
136-
url = 'https://github.com/wiremock/wiremock-state-extension'
137-
138-
139-
scm {
140-
connection = 'https://github.com/wiremock/wiremock-state-extension.git'
141-
developerConnection = 'https://github.com/wiremock/wiremock-state-extension.git'
142-
url = 'https://github.com/wiremock/wiremock-state-extension.git'
143-
}
144-
145-
licenses {
146-
license {
147-
name = 'The Apache Software License, Version 2.0'
148-
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
149-
distribution = 'repo'
150-
}
151-
}
152-
153-
developers {
154-
developer {
155-
id = 'dirkbolte'
156-
name = 'Dirk Bolte'
157-
158-
}
159-
}
160-
}
161-
}
162-
standaloneJar(MavenPublication) { publication ->
163-
artifactId = "${baseArtifact}-standalone"
164-
165-
project.shadow.component(publication)
166-
167-
artifact sourcesJar
168-
artifact javadocJar
169-
170-
pom {
171-
172-
name = "${baseArtifact}-standalone"
173-
description = 'A WireMock extension to transfer state in between stubs - to be used with WireMock standalone'
174-
url = 'https://github.com/wiremock/wiremock-state-extension'
175-
176-
177-
scm {
178-
connection = 'https://github.com/wiremock/wiremock-state-extension.git'
179-
developerConnection = 'https://github.com/wiremock/wiremock-state-extension.git'
180-
url = 'https://github.com/wiremock/wiremock-state-extension.git'
181-
}
182-
183-
licenses {
184-
license {
185-
name = 'The Apache Software License, Version 2.0'
186-
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
187-
distribution = 'repo'
188-
}
189-
}
190-
191-
developers {
192-
developer {
193-
id = 'dirkbolte'
194-
name = 'Dirk Bolte'
195-
196-
}
197-
}
198-
}
199-
}
200-
}
201-
}
202-
203-
task checkReleasePreconditions {
204-
doLast {
205-
def REQUIRED_GIT_BRANCH = 'HEAD'
206-
def currentGitBranch = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim()
207-
assert currentGitBranch == REQUIRED_GIT_BRANCH, "Must be on the $REQUIRED_GIT_BRANCH branch in order to release to Sonatype"
208-
}
209-
}
210-
publish.dependsOn checkReleasePreconditions
211-
publish.dependsOn 'signStandaloneJarPublication'
212-
publish.dependsOn 'signMavenJavaPublication'
213-
214-
// FIXME: remove after https://github.com/gradle/gradle/issues/26091
215-
tasks.withType(AbstractPublishToMaven).configureEach {
216-
def signingTasks = tasks.withType(Sign)
217-
mustRunAfter(signingTasks)
218-
}
219-
220-
repositories {
221-
mavenCentral()
222-
mavenLocal()
223-
}
224-
225-
dependencies {
226-
implementation("org.wiremock:wiremock:${versions.wiremock}")
227-
implementation("com.github.ben-manes.caffeine:caffeine:${versions.caffeine}")
228-
implementation("com.github.jknack:handlebars-helpers:${versions.handlebars}") {
229-
exclude group: 'org.mozilla', module: 'rhino'
230-
}
231-
232-
testImplementation(platform("org.junit:junit-bom:${versions.junit}"))
233-
testImplementation('org.junit.jupiter:junit-jupiter')
234-
testImplementation("org.assertj:assertj-core:${versions.assertj}")
235-
testImplementation(platform("io.rest-assured:rest-assured-bom:${versions.restAssured}"))
236-
testImplementation("io.rest-assured:rest-assured")
237-
testImplementation("org.awaitility:awaitility:${versions.awaitility}")
238-
}
239-
240-
241-
sourceCompatibility = 11
242-
targetCompatibility = 11
243-
244-
compileJava {
245-
options.encoding = 'UTF-8'
246-
}
247-
248-
compileTestJava {
249-
options.encoding = 'UTF-8'
250-
}
251-
assemble.dependsOn jar, shadowJar
252-
253-
test {
254-
useJUnitPlatform()
255-
testLogging {
256-
events "passed", "skipped", "failed"
257-
}
258-
}
259-
260-
idea {
261-
project {
262-
jdkName = '11'
263-
languageLevel = '11'
264-
}
265-
}
266-
267-
nexusPublishing {
268-
// See https://github.com/wiremock/community/blob/main/infra/maven-central.md
269-
repositories {
270-
sonatype {
271-
// TODO: allow configuring destinations for oss1
272-
// nexusUrl.set(uri("https://oss.sonatype.org/service/local/"))
273-
// snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/"))
274-
def envUsername = providers.environmentVariable("OSSRH_USERNAME").orElse("").get()
275-
def envPassword = providers.environmentVariable("OSSRH_TOKEN").orElse("").get()
276-
if (!envUsername.isEmpty() && !envPassword.isEmpty()) {
277-
username.set(envUsername)
278-
password.set(envPassword)
279-
}
280-
}
281-
}
282-
}
283-

gradle.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
baseArtifact = wiremock-state-extension
2+
version = 0.6.0-SNAPSHOT
3+
description = A WireMock extension to transfer state in between stubs
4+
githubRepo = wiremock-state-extension
5+
developer.id=dirkbolte
6+
developer.name=Dirk Bolte
7+
developer.email[email protected]

0 commit comments

Comments
 (0)