Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task 'contracts' is not available in gradle plugin #1795

Closed
bwgjoseph opened this issue Jun 9, 2022 · 10 comments
Closed

task 'contracts' is not available in gradle plugin #1795

bwgjoseph opened this issue Jun 9, 2022 · 10 comments

Comments

@bwgjoseph
Copy link

Describe the bug

contracts task does not seem to exist in org.springframework.cloud.contract:3.1.3 gradle plugin

Sample

This is the full build.gradle

build.gradle - click to expand
plugins {
	id 'org.springframework.boot' version '2.7.0'
	id 'io.spring.dependency-management' version '1.0.11.RELEASE'
	id 'org.springframework.cloud.contract' version '3.1.3'
	id 'java'
}

group = 'com.bwgjoseph'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

configurations {
	compileOnly {
		extendsFrom annotationProcessor
	}
}

repositories {
	mavenCentral()
}

ext {
	set('springCloudVersion', "2021.0.3")
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-web'
	compileOnly 'org.projectlombok:lombok'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'org.springframework.cloud:spring-cloud-starter-contract-verifier'
}

dependencyManagement {
	imports {
		mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
	}
}

tasks.named('contracts') {
	testFramework = org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT5
}

tasks.named('contractTest') {
	useJUnitPlatform()
}

tasks.named('test') {
	useJUnitPlatform()
}

Faced with this

image


I removed the contracts task and ran ./gradlew tasks and I have all these tasks but contracts is definitely not one of them.

Application tasks
-----------------
bootRun - Runs this project as a Spring Boot application.

Build tasks
-----------
assemble - Assembles the outputs of this project.
bootBuildImage - Builds an OCI image of the application using the output of the bootJar task
bootJar - Assembles an executable jar archive containing the main classes and their dependencies.
bootJarMainClassName - Resolves the name of the application's main class for the bootJar task.
bootRunMainClassName - Resolves the name of the application's main class for the bootRun task.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
contractTestClasses - Assembles contract test classes.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'scc-provider'.
dependencies - Displays all dependencies declared in root project 'scc-provider'.
dependencyInsight - Displays the insight into a specific dependency in root project 'scc-provider'.
dependencyManagement - Displays the dependency management declared in root project 'scc-provider'.
help - Displays a help message.
javaToolchains - Displays the detected java toolchains.
outgoingVariants - Displays the outgoing variants of root project 'scc-provider'.
projects - Displays the sub-projects of root project 'scc-provider'.
properties - Displays the properties of root project 'scc-provider'.
tasks - Displays the tasks runnable from root project 'scc-provider'.

Verification tasks
------------------
check - Runs all checks.
contractTest - Runs the contract tests
copyContracts - Copies contracts to the output folder
generateClientStubs - Generate client stubs from the contracts
generateContractTests - Generate server tests from the contracts
publishStubsToScm - The generated stubs get committed to the SCM repo and pushed to origin
test - Runs the test suite.
verifierStubsJar - Creates the stubs JAR task

Was it removed from the latest plugin? Or did I configure something wrongly?

Thanks!

@marcingrzejszczak
Copy link
Contributor

I don't recall ever having a contracts task, where did you take it from?

@bwgjoseph
Copy link
Author

Two sources actually

  1. start.spring.io, you can click here to see

image

However, note that the one generated by start.spring.io is actually using the older buildscript declaration

image

Though, it shouldn't affect

  1. spring-cloud-contract-samples - click here

image

@marcingrzejszczak
Copy link
Contributor

marcingrzejszczak commented Jun 10, 2022

@bwgjoseph
Copy link
Author

I'm not an expert by any means, too. If it's there, why would Gradle then complain that it isn't? And even listing the tasks list doesn't show the contracts task

@marcingrzejszczak
Copy link
Contributor

ping @shanman190

@shanman190
Copy link
Contributor

So like @marcingrzejszczak mentioned, there hasn't ever been a contracts task. However, there is a contracts extension. It appears that Spring Initializer has a bug specifically with how it's trying to configure the extension and is accidentally using the task configuration instead which isn't valid.

The correct configuration for build.gradle would be:

contracts {
    testFramework = org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT5
}

I've filed spring-io/start.spring.io gh-938 to get the issue resolved.

@bwgjoseph
Copy link
Author

Thanks for the clarification.

Wasn't aware of extensions until now. And that extensions is used to provide input to the tasks.

@bwgjoseph
Copy link
Author

Also, I re-configured to this and I am able to build now

contracts {
	testFramework = org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT5
	failOnNoContracts = false
}

tasks.named('contractTest') {
	useJUnitPlatform()
}

@shanman190
Copy link
Contributor

shanman190 commented Jun 13, 2022

@bwgjoseph, if you feel like we have solved your problem, I think we can close this issue and rely on the linked issue to Spring Initializer.

@bwgjoseph
Copy link
Author

Yes, sure. Thank you for both your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants