Attempt to keep Kotlin totally off the classpath (#1558)

* Attempt to keep Kotlin totally off the classpath

* Add version header for new class

* Fix a few bugs with the samples and provide better debugging output for javaexec

* Use main consistently

* Fix Gradle's published pom and use maven-publish plugin consistently throughout plugin and samples

* Re-add groovydoc jar

* Have assemble create the groovydoc jar

* Switch to publishToMavenLocal

* Sync dependencies with pom.xml and fix null provider for Gradle versions less than 6.2

* Perform quoting conditionally for Windows only

* Add jsch, aether, and shaded libraries to round out compatibility

* Ensure contract tests are generated before kotlin compile task
This commit is contained in:
Shannon Pamperl
2020-12-03 03:24:55 -06:00
committed by GitHub
parent a3268f908a
commit 7804933b21
25 changed files with 644 additions and 275 deletions

View File

@@ -1,15 +1,9 @@
buildscript {
repositories {
mavenCentral()
mavenLocal()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url "https://repo.spring.io/release" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${findProperty('bootVersion') ?: bootVersion}"
classpath "org.springframework.cloud:spring-cloud-contract-gradle-plugin:${project.findProperty('verifierVersion') ?: verifierVersion}"
}
plugins {
id "groovy"
id "org.springframework.boot"
id "io.spring.dependency-management"
id "org.springframework.cloud.contract"
id "maven-publish"
}
group = 'com.example'
@@ -23,17 +17,10 @@ repositories {
maven { url "https://repo.spring.io/release" }
}
apply plugin: 'groovy'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven-publish'
apply plugin: 'maven'
apply plugin: 'spring-cloud-contract'
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:$BOM_VERSION"
mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${project.findProperty('verifierVersion') ?: verifierVersion}"
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${BOM_VERSION}"
mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${verifierVersion}"
}
}
@@ -50,7 +37,17 @@ dependencies {
// end::dependencies[]
}
contracts {
baseClassMappings {
baseClassMapping('.*standalone.*', 'com.example.fraud.FraudBaseWithStandaloneSetup')
baseClassMapping('.*webapp.*', 'com.example.fraud.FraudBaseWithWebAppSetup')
}
}
generateClientStubs.enabled = false
test {
useJUnitPlatform()
systemProperty 'spring.profiles.active', 'gradle'
testLogging {
exceptionFormat = 'full'
@@ -65,29 +62,12 @@ test {
}
}
contracts {
baseClassMappings {
baseClassMapping('.*standalone.*', 'com.example.fraud.FraudBaseWithStandaloneSetup')
baseClassMapping('.*webapp.*', 'com.example.fraud.FraudBaseWithWebAppSetup')
}
}
generateClientStubs.enabled = false
task stubsJar(type: Jar, dependsOn: ['copySnippets', 'copySources', 'copyClasses']) {
baseName = project.name
classifier = 'stubs'
from project.file("${project.buildDir}/stubs")
}
artifacts {
archives stubsJar
}
test {
useJUnitPlatform()
}
task copySnippets(type: Copy, dependsOn: test) {
from "target/snippets/stubs"
into "${project.buildDir}/stubs/META-INF/${project.group}/${project.name}/${project.version}/mappings"
@@ -105,6 +85,25 @@ task copyClasses(type: Copy) {
into "${project.buildDir}/stubs/"
}
publishing {
publications {
maven(MavenPublication) {
artifact bootJar
artifact stubsJar
// https://github.com/spring-gradle-plugins/dependency-management-plugin/issues/273
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
}
}
}
clean.doFirst {
delete 'target/snippets/stubs'
delete "~/.m2/repository/com/example/http-server-restdocs-gradle"

View File

@@ -225,8 +225,7 @@
<arguments>
<argument>clean</argument>
<argument>build</argument>
<!-- For some reason publishToMavenLocal doesn't work... Please don't troll Gradle ;)-->
<argument>install</argument>
<argument>publishToMavenLocal</argument>
<argument>
-PverifierVersion=${spring-cloud-contract.version}
</argument>

View File

@@ -1 +1,22 @@
rootProject.name = 'http-server-restdocs'
pluginManagement {
repositories {
mavenLocal()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
gradlePluginPortal()
}
plugins {
id 'org.springframework.boot' version "${bootVersion}"
id "io.spring.dependency-management" version "1.0.10.RELEASE"
}
resolutionStrategy {
eachPlugin {
// protects us in case the gradle-portal-plugin hasn't yet been published by Maven
if (requested.id.id == 'org.springframework.cloud.contract') {
useModule("org.springframework.cloud:spring-cloud-contract-gradle-plugin:${verifierVersion}")
}
}
}
}
rootProject.name = 'http-server-restdocs-gradle'

View File

@@ -40,7 +40,7 @@ import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.docu
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
@SpringBootTest(classes = Application.class)
@AutoConfigureRestDocs
@AutoConfigureRestDocs(outputDir = "target/snippets")
@AutoConfigureMockMvc
@AutoConfigureJsonTesters
public class StubGeneratorTests {