Convert Gradle plugin from Groovy to Java (#1480)

* Migrate ContractsCopyTask from Groovy to Java

* Convert code to Java

* Refactor ContractsCopyTask

* Migrate GenerateClientStubsFromDslTask from Groovy to Java.

* Refactor GenerateClientStubsFromDslTask

* Clean up configuration of stubsJar

* Migrate GenerateServerTestsTask from Groovy to Java

* Refactor GenerateServerTestsTask

* Migrate PublishStubsToScmTask from Groovy to Java

* Refactor PublishStubsToScmTask

* Remove dead code

* Add additional test to ensure merged contract repository settings works the same as it did before. Add .get() calls to trigger task configuration otherwise, we can miss errors with task configuration.

* Fixup all visibility modifiers and drop any deprecated functionality

* Migrate plugin from Groovy to Java

* Refactor plugin from Groovy to Java

* Fixup project.version where it might not be correctly available yet

* Fix tests that were broken

* Fix functional testing that was failing

* Update functional tests to ensure that up-to-date checks are running as expected

* Added comment around deleteStubsAfterTest in each of the tasks where it is used, to remind editors what the property is for.

* Enable support for build cache

* Reconcile documentation with code

* Remove TODO that has been answered

* Add documentation on how to customize the verifierStubsJar

* Fix failing test

* Allow contractsDirectory to be null

* Fix failing tests

* Move all main source code to java source set
This commit is contained in:
Shannon Pamperl
2020-10-02 10:39:53 -05:00
committed by GitHub
parent b12fc7ae32
commit e91b91efba
25 changed files with 1724 additions and 1460 deletions

View File

@@ -228,22 +228,13 @@ pseudocode):
contracts {
testFramework ='JUNIT'
testMode = 'MockMvc'
generatedTestSourcesDir = project.file("${project.buildDir}/generated-test-sources/contracts")
generatedTestJavaSourcesDir = project.file("${project.buildDir}/generated-test-sources/contractTest/java")
generatedTestGroovySourcesDir = project.file("${project.buildDir}/generated-test-sources/contractTest/groovy")
generatedTestResourcesDir = project.file("${project.buildDir}/generated-test-resources/contracts")
contractsDslDir = project.file("${project.rootDir}/src/test/resources/contracts")
contractsDslDir = project.file("${project.projectDir}/src/test/resources/contracts")
basePackageForTests = 'org.springframework.cloud.verifier.tests'
stubsOutputDir = project.file("${project.buildDir}/stubs")
sourceSet = null
// the following properties are used when you want to provide where the JAR with contract lays
contractDependency {
stringNotation = ''
}
contractsPath = ''
contractsWorkOffline = false
contractRepository {
cacheDownloadedContracts(true)
}
}
tasks.create(type: Jar, name: 'verifierStubsJar', dependsOn: 'generateClientStubs') {
@@ -278,6 +269,52 @@ contracts {
----
====
To download contracts from a remote source, you can use the following snippets as needed:
====
[source,groovy,indent=0]
----
contracts {
// If your contracts exist in a JAR archive published to a Maven repository
contractDependency {
stringNotation = ''
// OR
groupId = ''
artifactId = ''
version = ''
classifier = ''
}
// If your contracts exist in a Git SCM repository
contractRepository {
repositoryUrl = ''
// username = ''
// password = ''
}
// controls the nested location to find the contracts in either the JAR or Git SCM source
contractsPath = ''
}
----
====
Since we are using Gradle's Jar packaging task, there are several options and capabilities that you may wish to utilize to further extend what is created by the `verifierStubsJar`. In order to do this, you would use the native mechanisms provided directly by Gradle for customizing an existing task like so:
NOTE: for the sake of the example, we desire to add a `git.properties` file to the `verifierStubsJar`.
====
[source,groovy,inden=0]
----
verifierStubsJar {
from("${buildDir}/resources/main/") {
include("git.properties")
}
}
----
====
It should also be noted that as of 3.0.0, the default publication has been disabled. As a result this means, that you are able to create any named jar and publish it as you would normally have done via Gradle configuration options. This means that you can build a jar file customized just the way you would like and publish that for absolute full control over the jar's layout and contents.
[[gradle-configuration-options]]
== Configuration Options
@@ -299,25 +336,24 @@ use Spock classes, the class is `spock.lang.Specification`.
setting takes precedence over `baseClassForTests`.
* `baseClassMappings`: Explicitly maps a contract package to a FQN of a base class. This
setting takes precedence over `packageWithBaseClasses` and `baseClassForTests`.
* `ruleClassForTests`: Specifies a rule that should be added to the generated test
classes.
* `ignoredFiles`: Uses an `Antmatcher` to allow defining stub files for which processing
should be skipped. By default, it is an empty array.
* `contractsDslDir`: Specifies the directory that contains contracts written by using the
GroovyDSL. By default, its value is `$rootDir/src/test/resources/contracts`.
GroovyDSL. By default, its value is `$projectDir/src/test/resources/contracts`.
* `generatedTestSourcesDir`: Specifies the test source directory where tests generated
from the Groovy DSL should be placed. By default, its value is
`$buildDir/generated-test-sources/contracts`.
from the Groovy DSL should be placed. (Deprecrated)
* `generatedTestJavaSourcesDir`: Specifies the test source directory where Java/JUnit tests generated from the Groovy DSL should be placed. By default, it's value is `$buildDir/generated-tes-sources/contractTest/java`.
* `generatedTestGroovySourcesDir`: Specifies the test source directory where Groovy/Spock tests generated from the Groovy DSL should be placed. By default, it's value is `$buildDir/generated-test-sources/contractTest/groovy`.
* `generatedTestResourcesDir`: Specifies the test resource directory where resources used by the tests generated
from the Groovy DSL should be placed. By default, its value is
`$buildDir/generated-test-resources/contracts`.
`$buildDir/generated-test-resources/contractTest`.
* `stubsOutputDir`: Specifies the directory where the generated WireMock stubs from
the Groovy DSL should be placed.
* `testFramework`: Specifies the target test framework to be used. Currently, Spock, JUnit 4 (`TestFramework.JUNIT`) and
JUnit 5 are supported, with JUnit 4 being the default framework.
* `contractsProperties`: A map that contains properties to be passed to Spring Cloud Contract
components. Those properties might be used by (for example) built-in or custom Stub Downloaders.
* `sourceSet`: Source set where the contracts are stored. If not provided will assume `test` (for example, `project.sourceSets.test.java` for JUnit or `project.sourceSets.test.groovy` for Spock).
* `sourceSet`: Source set where the contracts are stored. If not provided will assume `contractTest` (for example, `project.sourceSets.contractTest.java` for JUnit or `project.sourceSets.contractTest.groovy` for Spock).
You can use the following properties when you want to specify the location of the JAR
that contains the contracts: