Disable stubsJar publication by default. (#1464)

Fixes gh-1168.
This commit is contained in:
Shannon Pamperl
2020-08-07 09:01:53 -05:00
committed by GitHub
parent 0644d7af1c
commit ba22c687c8
6 changed files with 62 additions and 18 deletions

View File

@@ -15,6 +15,7 @@ following sections:
* <<gradle-single-base-class>>
* <<gradle-different-base-classes>>
* <<gradle-invoking-generated-tests>>
* <<gradle-publishing-stubs-to-artifact-repo>>
* <<gradle-pushing-stubs-to-scm>>
* <<gradle-consumer>>
@@ -251,25 +252,12 @@ tasks.create(type: Jar, name: 'verifierStubsJar', dependsOn: 'generateClientStub
from contractVerifier.stubsOutputDir
}
project.artifacts {
archives task
}
tasks.create(type: Copy, name: 'copyContracts') {
from contracts.contractsDslDir
into contracts.stubsOutputDir
}
verifierStubsJar.dependsOn 'copyContracts'
publishing {
publications {
stubs(MavenPublication) {
artifactId project.name
artifact verifierStubsJar
}
}
}
----
====
@@ -446,6 +434,35 @@ the following command:
----
====
[[gradle-publishing-stubs-to-artifact-repo]]
== Publishing Stubs to Artifact Repository
If you use an binary artifact repository to keep the stubs,
you will need to configure the publishing section for Gradle to
include the `verifierStubsJar`. To do that, you can use the
example configuration below:
====
[source,groovy,indent=0]
----
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
// other configuration
artifact verifierStubsJar
}
}
}
----
====
Since 3.0.0, the internal stubs publication has been deprecated
and disabled by default. It is recommended to include the
`verifierStubsJar` with one of your own publications.
[[gradle-pushing-stubs-to-scm]]
== Pushing Stubs to SCM

View File

@@ -233,7 +233,10 @@ public class ContractVerifierExtension implements Serializable {
/**
* Is set to true will not provide the default publication task
*
* @deprecated - with 3.0.0, the user should include stubs with their own publication(s)
*/
@Deprecated
private Property<Boolean> disableStubPublication;
/**
@@ -276,7 +279,7 @@ public class ContractVerifierExtension implements Serializable {
this.deleteStubsAfterTest = objects.property(Boolean.class).convention(true);
this.convertToYaml = objects.property(Boolean.class).convention(false);
this.contractsProperties = objects.mapProperty(String.class, String.class).convention(new HashMap<>());
this.disableStubPublication = objects.property(Boolean.class).convention(false);
this.disableStubPublication = objects.property(Boolean.class).convention(true);
this.sourceSet = objects.property(String.class);
this.objects = objects;
}
@@ -578,10 +581,12 @@ public class ContractVerifierExtension implements Serializable {
contractsProperties.set(map);
}
@Deprecated
public Property<Boolean> getDisableStubPublication() {
return disableStubPublication;
}
@Deprecated
public void setDisableStubPublication(boolean disableStubPublication) {
this.disableStubPublication.set(disableStubPublication);
}

View File

@@ -25,7 +25,7 @@ import org.gradle.api.plugins.GroovyPlugin
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
import org.gradle.api.tasks.TaskProvider
import org.gradle.jvm.tasks.Jar
import org.gradle.api.tasks.bundling.Jar
import org.springframework.cloud.contract.verifier.config.TestFramework
@@ -167,6 +167,7 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
return task
}
@Deprecated
private void createAndConfigureMavenPublishPlugin(TaskProvider<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")
@@ -193,7 +194,9 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
}
@CompileDynamic
@Deprecated
private void setPublications(def publishingExtension, TaskProvider<Task> stubsTask) {
project.logger.warn("Spring Cloud Contract Verifier Plugin: Creating stubs publication is deprecated")
publishingExtension.publications {
stubs(MavenPublication) {
artifactId "${project.name}"
@@ -212,6 +215,7 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
}
@CompileDynamic
@Deprecated
private boolean hasStubsPublication(def publishingExtension) {
try {
return publishingExtension.publications.getByName('stubs')
@@ -251,6 +255,7 @@ class SpringCloudContractVerifierGradlePlugin implements Plugin<Project> {
return task
}
@Deprecated
private boolean classIsOnClasspath(String className) {
try {
Class.forName(className)

View File

@@ -90,11 +90,19 @@ class ContractVerifierSpec extends Specification {
* project.evaluate() is used here in order to trigger the evaluation lifecycle of a project.
* This method is currently exposed via the internal API and is subject to change, however, Gradle
* does not yet expose a way to test this portion of the lifecycle.
*
* In the next version, this test will be completely removed as publication will be fully a user
* responsibility.
*/
def "should configure maven-publish plugin, if available"() {
@Deprecated
def "should configure maven-publish plugin, if enabled"() {
given:
project.plugins.apply(MavenPublishPlugin)
project.plugins.apply(SpringCloudContractVerifierGradlePlugin)
ContractVerifierExtension extension = project.getExtensions().findByType(ContractVerifierExtension)
extension.with {
disableStubPublication = false
}
project.evaluate() // Currently internal method to trigger afterEvaluate blocks.
expect:

View File

@@ -30,7 +30,6 @@ group = 'org.springframework.cloud.testprojects'
subprojects {
apply plugin: 'groovy'
apply plugin: 'maven-publish'
sourceCompatibility = 1.8
targetCompatibility = 1.8
@@ -61,6 +60,7 @@ configure([project(':fraudDetectionService'), project(':loanApplicationService')
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.springframework.cloud.contract'
apply plugin: 'maven-publish'
// tag::jar_setup[]
ext {
@@ -71,7 +71,6 @@ configure([project(':fraudDetectionService'), project(':loanApplicationService')
// Automatically added by plugin:
// copyContracts - copies contracts to the output folder from which JAR will be created
// verifierStubsJar - JAR with a provided stub suffix
// the presented publication is also added by the plugin but you can modify it as you wish
publishing {
publications {

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
import org.gradle.api.publish.PublishingExtension
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties
import org.springframework.cloud.contract.verifier.config.TestFramework
import org.springframework.cloud.contract.verifier.config.TestMode
@@ -77,6 +78,15 @@ configure(listOf(project(":fraudDetectionService"), project(":loanApplicationSer
stubsOutputDir.set(file("${project.buildDir}/production/${project.name}-stubs/"))
}
configure<PublishingExtension> {
publications {
create<MavenPublication>("stubs") {
artifactId = "${project.name}-stubs"
artifact(tasks.named<Jar>("verifierStubsJar").get())
}
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
exclude(module = "spring-boot-starter-tomcat")