Home > Mobile >  Spring Cloud Contract Tests with Gradle - publish stubs to local repository
Spring Cloud Contract Tests with Gradle - publish stubs to local repository

Time:07-08

I am making a Gradle project with several different technologies, one of which is Spring Cloud Contract.

According to this enter image description here

Local maven repository of the project:

enter image description here

As you can see the stubs jar is not published to maven local.

My gradle.build:

buildscript {
    dependencies {
        classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:3.1.3"
    }
}

plugins {
    id 'org.springframework.boot'
    id 'io.spring.dependency-management'
    id 'java'
    id "org.springframework.cloud.contract"
    id 'maven-publish'
    id 'java-library'
}

jar {
    archivesBaseName = 'pcshop'
}

group 'com.capgemini'
version '1.0-SNAPSHOT'

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:3.1.3"
    }
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
    implementation 'org.springframework.boot:spring-boot-starter-web:2.7.0'
    implementation 'org.springframework.kafka:spring-kafka:2.8.5'
    implementation group: 'org.codehaus.jettison', name: 'jettison', version: '1.5.0'
    implementation 'org.apache.geode:geode-core:1.14.4'
    testImplementation 'org.springframework.boot:spring-boot-starter-test:2.7.0'
    testImplementation 'org.springframework.kafka:spring-kafka-test:2.8.5'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
    implementation 'org.springframework.kafka:spring-kafka:2.8.7'
    testImplementation 'org.springframework.kafka:spring-kafka-test:2.8.7'
    implementation 'org.springframework.cloud:spring-cloud-contract-maven-plugin:3.1.3'
    testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-verifier:3.1.3'
    testImplementation 'org.springframework.cloud:spring-cloud-contract-wiremock:3.1.3'
    testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-stub-runner:3.1.3'
    testImplementation 'org.springframework.cloud:spring-cloud-contract-stub-runner:3.1.3'
}

task sourceJar(type: Jar) {
    from sourceSets.main.allJava
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java

            artifact sourceJar {
                classifier "sources"
            }
        }
    }
}

contracts {
    baseClassForTests = 'com.capgemini.pcshop.BaseTestClass'
}

test {
    useJUnitPlatform()
}

CodePudding user response:

That's because we no longer create the proper publication out of the box. You can read more about this here https://docs.spring.io/spring-cloud-contract/docs/current/reference/html/gradle-project.html#gradle-publishing-stubs-to-artifact-repo

To solve your problem just create the following publication

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java

            artifact sourceJar {
                classifier "sources"
            }

            
            artifact verifierStubsJar
        }
    }
}
  • Related