Update integration test to take advantage of java-gradle-plugin

This plugin is required when using the withPluginClasspath(..) method,
but during Gradle execution it creates a listing of the classpath that
the plugin under test would have. We can then use that explicitly to
build up the necessary classpath in the init.gradle script for loading
the necessary classes to run integration tests against the plugin
without needing to copy all of the jar files into a folder via a Gradle
task.
This commit is contained in:
Shannon Pamperl
2019-08-29 16:12:38 -05:00
parent 6f534b2eee
commit d03a8eb960
2 changed files with 5 additions and 18 deletions

View File

@@ -25,9 +25,7 @@ ext {
repoUser = System.getenv('REPO_USERNAME') ?: project.findProperty('REPO_USERNAME') ?: ''
repoPass = System.getenv('REPO_PASSWORD') ?: project.findProperty('REPO_PASSWORD') ?: ''
contractVerifierGradlePluginLibsDir = "$buildDir/contractVerifier-gradle-plugin-libs"
testSystemProperties = [
'contract-gradle-plugin-libs-dir': contractVerifierGradlePluginLibsDir,
"WORK_OFFLINE" : gradle.startParameter.isOffline() ? 'TRUE' : 'FALSE'
]
JavaVersion javaVer = JavaVersion.current()
@@ -38,6 +36,7 @@ ext {
project.version = findProperty('verifierVersion')
apply plugin: 'groovy'
apply plugin: "java-gradle-plugin"
apply from: "$rootDir/gradle/release.gradle"
apply plugin: 'eclipse'
//apply plugin: "jacoco"
@@ -65,8 +64,6 @@ task allInsight(type: DependencyInsightReportTask) {}
configurations {
// fixing the groovydoc issue https://stackoverflow.com/questions/20618857/gradle-task-groovydoc-failing-with-noclassdeffounderror
jansi.extendsFrom(runtime)
contractVerifierGradlePluginLibs
}
dependencies {
@@ -89,7 +86,6 @@ dependencies {
testCompile 'info.solidsoft.spock:spock-global-unroll:0.5.0'
testCompile gradleTestKit()
checkstyle "org.springframework.cloud:spring-cloud-build:${springCloudBuildVersion}"
}
task libtest() {
@@ -121,19 +117,9 @@ groovydoc {
}
dependencies {
contractVerifierGradlePluginLibs project
jansi 'org.fusesource.jansi:jansi:1.11'
}
task archiveContractVerifierGradlePluginLibsDependencies(type: Sync) {
enabled = !incompatibleJdk
from configurations.contractVerifierGradlePluginLibs.resolvedConfiguration.resolvedArtifacts.collect { it.file }
into contractVerifierGradlePluginLibsDir
}
archiveContractVerifierGradlePluginLibsDependencies.dependsOn project.tasks.jar
test.dependsOn archiveContractVerifierGradlePluginLibsDependencies
/*jacoco {
toolVersion = "0.7.7.201606060606"
}

View File

@@ -51,14 +51,15 @@ abstract class ContractVerifierIntegrationSpec extends Specification {
protected void setupForProject(String projectRoot) {
copyResourcesToRoot(projectRoot)
String gradlePluginSysProp = System.getProperty("contract-gradle-plugin-libs-dir")
String gradlePluginLibsDir = (gradlePluginSysProp ?: new File("build/").absolutePath.toString()).replace('\\', '\\\\')
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 fileTree(dir: '$gradlePluginLibsDir', include: '*.jar')
classpath(files(\"${classpath.join("\",\"")}\"))
}
}
}