Switch to plugins{} apply syntax
Now that Spring Cloud Contract is generating a plugin marker, it's much
easier to functionally test using Gradle TestKit by utilizing the
withPluginClasspath() and the 'java-gradle-plugin' Gradle plugin. Since
Gradle recommends new users, as well as new plugin authors, to use the
plugin markers and plugins{} syntax we should also follow that same
path. Especially given that there has been feature parity with the
buildscirpt{} block some releases ago.
This commit is contained in:
@@ -51,21 +51,6 @@ abstract class ContractVerifierIntegrationSpec extends Specification {
|
||||
|
||||
protected void setupForProject(String projectRoot) {
|
||||
copyResourcesToRoot(projectRoot)
|
||||
Properties pluginClasspathProperties = new Properties()
|
||||
pluginClasspathProperties.load(this.class.getResourceAsStream("/plugin-under-test-metadata.properties"))
|
||||
List<String> classpath = pluginClasspathProperties.getProperty("implementation-classpath").split(";").collect { it.replaceAll("\\\\", "/") }
|
||||
|
||||
initFile.write """
|
||||
allprojects {
|
||||
buildscript {
|
||||
dependencies {
|
||||
classpath(files(\"${classpath.join("\",\"")}\"))
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
// Extending buildscript is required when 'apply' is used.
|
||||
// 'GradleRunner#withPluginClasspath' can be used when plugin is added using 'plugins { id...'
|
||||
}
|
||||
|
||||
protected void switchToJunitTestFramework() {
|
||||
@@ -105,13 +90,10 @@ abstract class ContractVerifierIntegrationSpec extends Specification {
|
||||
}
|
||||
|
||||
protected BuildResult run(String... tasks) {
|
||||
List<String> arguments = new ArrayList<>()
|
||||
arguments.addAll(tasks)
|
||||
arguments.add("-I" + getInitFile().absolutePath)
|
||||
|
||||
return GradleRunner.create()
|
||||
.withProjectDir(testProjectDir)
|
||||
.withArguments(arguments)
|
||||
.withArguments(tasks)
|
||||
.withPluginClasspath()
|
||||
// .withDebug(true)
|
||||
.forwardOutput()
|
||||
.build()
|
||||
@@ -151,10 +133,6 @@ abstract class ContractVerifierIntegrationSpec extends Specification {
|
||||
return new File(testProjectDir, 'build.gradle')
|
||||
}
|
||||
|
||||
protected File getInitFile() {
|
||||
return new File(testProjectDir, 'init.gradle')
|
||||
}
|
||||
|
||||
protected boolean jarContainsContractVerifierContracts(String path) {
|
||||
assert fileExists(path)
|
||||
File rootFile = file(path)
|
||||
|
||||
@@ -14,18 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
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:${bootVersion}")
|
||||
}
|
||||
plugins {
|
||||
id("org.springframework.boot") apply false
|
||||
id("org.springframework.cloud.contract") apply false
|
||||
}
|
||||
|
||||
ext {
|
||||
@@ -69,7 +60,7 @@ subprojects {
|
||||
configure([project(':fraudDetectionService'), project(':loanApplicationService')]) {
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
apply plugin: 'spring-cloud-contract'
|
||||
apply plugin: 'org.springframework.cloud.contract'
|
||||
|
||||
// tag::jar_setup[]
|
||||
ext {
|
||||
|
||||
@@ -14,6 +14,24 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
maven { url "https://repo.spring.io/snapshot" }
|
||||
maven { url "https://repo.spring.io/milestone" }
|
||||
maven { url "https://repo.spring.io/release" }
|
||||
}
|
||||
resolutionStrategy {
|
||||
eachPlugin {
|
||||
if (requested.id.id == "org.springframework.boot") {
|
||||
useModule("org.springframework.boot:spring-boot-gradle-plugin:${bootVersion}")
|
||||
} else if (requested.id.id == "org.springframework.cloud.contract") {
|
||||
useModule("org.springframework.cloud:spring-cloud-contract-gradle-plugin:${verifierVersion}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include ':fraudDetectionService'
|
||||
include ':loanApplicationService'
|
||||
|
||||
@@ -14,21 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
buildscript {
|
||||
val bootVersion: String by extra
|
||||
|
||||
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:$bootVersion")
|
||||
}
|
||||
}
|
||||
|
||||
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties
|
||||
import org.springframework.cloud.contract.verifier.config.TestFramework
|
||||
import org.springframework.cloud.contract.verifier.config.TestMode
|
||||
@@ -36,7 +21,8 @@ import org.springframework.cloud.contract.verifier.plugin.ContractVerifierExtens
|
||||
|
||||
plugins {
|
||||
groovy
|
||||
// id("org.springframework.cloud.contract")
|
||||
id("org.springframework.boot") apply false
|
||||
id("org.springframework.cloud.contract") apply false
|
||||
}
|
||||
|
||||
val restAssuredVersion by extra("3.0.7")
|
||||
@@ -78,7 +64,7 @@ subprojects {
|
||||
configure(listOf(project(":fraudDetectionService"), project(":loanApplicationService"))) {
|
||||
apply(plugin = "org.springframework.boot")
|
||||
apply(plugin = "io.spring.dependency-management")
|
||||
apply(plugin = "spring-cloud-contract")
|
||||
apply(plugin = "org.springframework.cloud.contract")
|
||||
apply(plugin = "maven-publish")
|
||||
|
||||
configure<ContractVerifierExtension> {
|
||||
|
||||
@@ -14,6 +14,26 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
pluginManagement {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
maven(url = "https://repo.spring.io/snapshot")
|
||||
maven(url = "https://repo.spring.io/milestone")
|
||||
maven(url = "https://repo.spring.io/release")
|
||||
}
|
||||
resolutionStrategy {
|
||||
eachPlugin {
|
||||
if (requested.id.id == "org.springframework.boot") {
|
||||
val bootVersion: String by extra
|
||||
useModule("org.springframework.boot:spring-boot-gradle-plugin:$bootVersion")
|
||||
} else if (requested.id.id == "org.springframework.cloud.contract") {
|
||||
val verifierVersion: String by extra
|
||||
useModule("org.springframework.cloud:spring-cloud-contract-gradle-plugin:$verifierVersion")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include(":fraudDetectionService")
|
||||
include(":loanApplicationService")
|
||||
|
||||
Reference in New Issue
Block a user