Added option to disable adding custom publication; fixes #482

This commit is contained in:
Marcin Grzejszczak
2017-12-08 15:03:59 -08:00
parent c06e671292
commit d9790a4b17
6 changed files with 33 additions and 5 deletions

View File

@@ -169,6 +169,15 @@ class ContractVerifierExtension {
closure.call()
}
/**
* Is set to true will not provide the default publication task
*/
boolean disableStubPublication = false
void disableStubPublication(boolean disableStubPublication) {
this.disableStubPublication = disableStubPublication
}
@ToString
static class Dependency {
String groupId

View File

@@ -60,7 +60,7 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
setConfigurationDefaults(extension)
Task stubsJar = createAndConfigureStubsJarTasks(extension)
Task copyContracts = createAndConfigureCopyContractsTask(stubsJar, downloader, extension)
createAndConfigureMavenPublishPlugin(stubsJar)
createAndConfigureMavenPublishPlugin(stubsJar, extension)
createGenerateTestsTask(extension, copyContracts)
Task clientTask = createAndConfigureGenerateClientStubsFromDslTask(extension, copyContracts)
createAndConfigureGenerateWireMockClientStubsFromDslTask(extension, clientTask)
@@ -176,13 +176,17 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
return task
}
private void createAndConfigureMavenPublishPlugin(Task stubsTask) {
private void createAndConfigureMavenPublishPlugin(Task stubsTask, ContractVerifierExtension extension) {
if (!classIsOnClasspath("org.gradle.api.publish.maven.plugins.MavenPublishPlugin")) {
project.logger.debug("Maven Publish Plugin is not present - won't add default publication")
return
}
project.logger.debug("Spring Cloud Contract Verifier Plugin: Generating default publication")
project.afterEvaluate {
if (extension.isDisableStubPublication()) {
project.logger.info("You've switched off the stub publication - won't add default publication")
return
}
project.plugins.withType(MavenPublishPlugin) { def publishingPlugin ->
def publishingExtension = project.extensions.findByName('publishing')
if (!hasPublication(publishingExtension)) {

View File

@@ -73,11 +73,12 @@ abstract class ContractVerifierIntegrationSpec extends Specification {
Files.write(path, content.getBytes(UTF_8))
}
protected void runTasksSuccessfully(String... tasks) {
protected BuildResult runTasksSuccessfully(String... tasks) {
BuildResult result = run(tasks)
result.tasks.each {
assert it.outcome == TaskOutcome.SUCCESS || it.outcome == TaskOutcome.UP_TO_DATE || it.outcome == TaskOutcome.NO_SOURCE
}
return result
}
protected BuildResult validateTasksOutcome(BuildResult result, TaskOutcome expectedOutcome, String... tasks) {
@@ -134,7 +135,7 @@ abstract class ContractVerifierIntegrationSpec extends Specification {
}
protected File getBuildFile() {
return new File('build.gradle', testProjectDir)
return new File(testProjectDir, 'build.gradle')
}
protected boolean jarContainsContractVerifierContracts(String path) {

View File

@@ -146,6 +146,7 @@ class GradleContractsDownloaderSpec extends Specification {
repositoryUrl("foo")
cacheDownloadedContracts(false)
}
disableStubPublication(true)
}
and:
final AetherStubDownloader downloader = Mock(AetherStubDownloader)

View File

@@ -16,6 +16,7 @@
package org.springframework.cloud.contract.verifier.plugin
import org.gradle.testkit.runner.BuildResult
import spock.lang.Stepwise
@Stepwise
@@ -30,8 +31,19 @@ class SampleJerseyProjectSpec extends ContractVerifierIntegrationSpec {
given:
assert fileExists('build.gradle')
expect:
runTasksSuccessfully(checkAndPublishToMavenLocal())
BuildResult result = runTasksSuccessfully(checkAndPublishToMavenLocal())
jarContainsContractVerifierContracts('fraudDetectionService/build/libs')
!result.output.contains("You've switched off the stub publication")
}
def "should pass basic flow for Spock with disabled publication"() {
given:
assert fileExists('build.gradle')
expect:
String[] args = (checkAndPublishToMavenLocal().toList() << "-PdisablePublication") as String[]
BuildResult result = runTasksSuccessfully(args)
!fileExists('fraudDetectionService/build/libs')
result.output.contains("You've switched off the stub publication")
}
def "should pass basic flow for JUnit"() {

View File

@@ -130,6 +130,7 @@ configure(project(':fraudDetectionService')) {
}
generatedTestSourcesDir = file("${project.buildDir}/generated-test-sources/")
stubsOutputDir = stubsOutputDirRoot
disableStubPublication(project.hasProperty("disablePublication"))
}
}