Skip to content

Commit

Permalink
Created a subproject with standalone build so that we produce both ty…
Browse files Browse the repository at this point in the history
…pes of JAR and hopefully avoid shading issues
  • Loading branch information
tomakehurst committed Sep 21, 2023
1 parent af01919 commit 282142c
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 50 deletions.
112 changes: 62 additions & 50 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

buildscript {
repositories {
maven {
Expand All @@ -17,7 +15,6 @@ plugins {
id 'eclipse'
id 'project-report'
id 'com.diffplug.spotless' version '6.21.0'
id 'com.github.johnrengelman.shadow' version '8.1.0'
id "com.google.protobuf" version "0.9.4"
}

Expand All @@ -27,41 +24,45 @@ repositories {
}

group 'org.wiremock'

sourceCompatibility = 11
targetCompatibility = 11

ext {
versions = [
wiremock: "3.2.0",
grpc: "1.58.0",
protobuf: "3.24.0"
]

repoUser = this.hasProperty('sonatypeUser') ? sonatypeUser : 'default'
repoPassword = this.hasProperty('sonatypePassword') ? sonatypePassword : 'default'
}

dependencies {
api "org.wiremock:wiremock:$versions.wiremock"

api "io.grpc:grpc-bom:$versions.grpc"
api "io.grpc:grpc-protobuf:$versions.grpc"
api "io.grpc:grpc-stub:$versions.grpc"

implementation "io.grpc:grpc-servlet-jakarta:$versions.grpc"
implementation "com.google.protobuf:protobuf-java-util:$versions.protobuf"

implementation 'javax.annotation:javax.annotation-api:1.3.2'

testImplementation project(":")
testImplementation(platform('org.junit:junit-bom:5.10.0'))
testImplementation "org.junit.jupiter:junit-jupiter"
testImplementation "org.hamcrest:hamcrest-core:2.2"
testImplementation "org.hamcrest:hamcrest-library:2.2"
testImplementation 'org.awaitility:awaitility:4.2.0'

testImplementation "io.grpc:grpc-okhttp:$versions.grpc"
version = "0.1.0"

allprojects {
sourceCompatibility = 11
targetCompatibility = 11

ext {
versions = [
wiremock: "3.2.0",
grpc : "1.58.0",
protobuf: "3.24.0"
]

repoUser = this.hasProperty('sonatypeUser') ? sonatypeUser : 'default'
repoPassword = this.hasProperty('sonatypePassword') ? sonatypePassword : 'default'

pomInfo = {
name 'WireMock gRPC Extension'
url 'https://wiremock.org'
scm {
connection 'https://github.com/wiremock/wiremock-grpc-extension.git'
developerConnection 'https://github.com/wiremock/wiremock-grpc-extension.git'
url 'https://github.com/wiremock/wiremock-grpc-extension'
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/license/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'tomakehurst'
name 'Tom Akehurst'
}
}
}
}
}

spotless {
Expand All @@ -88,15 +89,26 @@ spotless {
}
}

shadowJar {
archiveBaseName.set('wiremock-grpc-extension')
archiveClassifier.set('')
dependencies {
compileOnlyApi "org.wiremock:wiremock:$versions.wiremock"

relocate "org.apache", 'wiremock.grpc.org.apache'
api "io.grpc:grpc-bom:$versions.grpc"
api "io.grpc:grpc-protobuf:$versions.grpc"
api "io.grpc:grpc-stub:$versions.grpc"

dependencies {
exclude(dependency('org.slf4j:slf4j-api'))
}
implementation "io.grpc:grpc-servlet-jakarta:$versions.grpc"
implementation "com.google.protobuf:protobuf-java-util:$versions.protobuf"

implementation 'javax.annotation:javax.annotation-api:1.3.2'

// testImplementation project(":")
testImplementation(platform('org.junit:junit-bom:5.10.0'))
testImplementation "org.junit.jupiter:junit-jupiter"
testImplementation "org.hamcrest:hamcrest-core:2.2"
testImplementation "org.hamcrest:hamcrest-library:2.2"
testImplementation 'org.awaitility:awaitility:4.2.0'

testImplementation "io.grpc:grpc-okhttp:$versions.grpc"
}

task sourcesJar(type: Jar, dependsOn: classes) {
Expand Down Expand Up @@ -134,16 +146,14 @@ publishing {

publications {
main(MavenPublication) { publication ->
artifactId = "${jar.getArchiveBaseName().get()}"
project.shadow.component(publication)

from components.java
artifact sourcesJar
artifact javadocJar
artifact testJar

pom.packaging 'jar'
pom.withXml {
asNode().appendNode('description', 'WireMock webhooks extension')
asNode().appendNode('description', 'Mock gRPC services with WireMock')
asNode().children().last() + pomInfo
}
}
Expand All @@ -152,8 +162,10 @@ publishing {

project.tasks.signMainPublication.dependsOn jar

assemble.dependsOn clean, jar

task release {
dependsOn clean, shadowJar, publishAllPublicationsToMavenRepository
dependsOn clean, assemble, publishAllPublicationsToMavenRepository
}

task localRelease {
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rootProject.name = 'wiremock-grpc-extension'

include 'wiremock-grpc-extension-standalone'
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public GrpcHttpServerFactory(BlobStore protoDescriptorStore) {
this.protoDescriptorStore = protoDescriptorStore;
}

@Override
public String getName() {
return "grpc";
}

@Override
public HttpServer buildHttpServer(
Options options,
Expand Down
163 changes: 163 additions & 0 deletions wiremock-grpc-extension-standalone/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
buildscript {
repositories {
maven {
url "https://oss.sonatype.org"
}
mavenCentral()
}
}

plugins {
id 'java-library'
id 'signing'
id 'maven-publish'
id 'idea'
id 'eclipse'
id 'project-report'
id 'com.diffplug.spotless' version '6.21.0'
id 'com.github.johnrengelman.shadow' version '8.1.0'
id "com.google.protobuf" version "0.9.4"
}

repositories {
mavenLocal()
mavenCentral()
}

group 'org.wiremock'
version = "0.1.0"

dependencies {
api project(":")
}

task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}

task testJar(type: Jar, dependsOn: testClasses) {
archiveClassifier.set('tests')
from sourceSets.test.output
}

signing {
required {
!version.toString().contains("SNAPSHOT") && (gradle.taskGraph.hasTask("uploadArchives") || gradle.taskGraph.hasTask("publish"))
}
sign publishing.publications
}

publishing {
repositories {
maven {
url 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
credentials {
username repoUser
password repoPassword
}
}
}

publications {
standalone(MavenPublication) { publication ->
artifactId = "${jar.getArchiveBaseName().get()}"
project.shadow.component(publication)

artifact sourcesJar
artifact javadocJar
artifact testJar

pom.packaging 'jar'
pom.withXml {
asNode().appendNode('description', 'Mock gRPC services with WireMock standalone')
asNode().children().last() + pomInfo
}
}
}
}

project.tasks.signStandalonePublication.dependsOn jar

assemble.dependsOn clean, shadowJar

task release {
dependsOn clean, assemble, publishAllPublicationsToMavenRepository
}

task localRelease {
dependsOn clean, assemble, publishToMavenLocal
}

shadowJar {
archiveBaseName.set('wiremock-grpc-extension-standalone')
archiveClassifier.set('')

relocate "io.grpc", 'wiremock.grpc.io.grpc'
relocate "io.perfmark", 'wiremock.grpc.io.perfmark'

relocate "org.mortbay", 'wiremock.org.mortbay'
relocate "org.eclipse", 'wiremock.org.eclipse'
relocate "org.codehaus", 'wiremock.org.codehaus'
relocate "com.google", 'wiremock.com.google'
relocate "com.google.thirdparty", 'wiremock.com.google.thirdparty'
relocate "com.fasterxml.jackson", 'wiremock.com.fasterxml.jackson'
relocate "org.apache", 'wiremock.org.apache'
relocate "org.xmlunit", 'wiremock.org.xmlunit'
relocate "org.hamcrest", 'wiremock.org.hamcrest'
relocate "org.skyscreamer", 'wiremock.org.skyscreamer'
relocate "org.json", 'wiremock.org.json'
relocate "net.minidev", 'wiremock.net.minidev'
relocate "com.jayway", 'wiremock.com.jayway'
relocate "org.objectweb", 'wiremock.org.objectweb'
relocate "org.custommonkey", "wiremock.org.custommonkey"
relocate "net.javacrumbs", "wiremock.net.javacrumbs"
relocate "net.sf", "wiremock.net.sf"
relocate "com.github.jknack", "wiremock.com.github.jknack"
relocate "org.antlr", "wiremock.org.antlr"
relocate "jakarta.servlet", "wiremock.jakarta.servlet"
relocate "org.checkerframework", "wiremock.org.checkerframework"
relocate "org.hamcrest", "wiremock.org.hamcrest"
relocate "org.slf4j", "wiremock.org.slf4j"
relocate "joptsimple", "wiremock.joptsimple"
exclude 'joptsimple/HelpFormatterMessages.properties'
relocate "org.yaml", "wiremock.org.yaml"
relocate "com.ethlo", "wiremock.com.ethlo"
relocate "com.networknt", "wiremock.com.networknt"

dependencies {
exclude(dependency('org.slf4j:slf4j-api'))
}
}

protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.24.3"
}

plugins {
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:$versions.grpc"
}
}
generateProtoTasks {
all()*.plugins {
grpc {
outputSubDir = 'java'
}
}

all().each { task ->
task.generateDescriptorSet = true
task.descriptorSetOptions.path = "$projectDir/src/test/resources/wiremock/grpc/services.dsc"
}
}
}

processTestResources.dependsOn generateProto
processTestResources.dependsOn generateTestProto

0 comments on commit 282142c

Please sign in to comment.