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

Contract tests not generated in producer failing with compile error #2101

Open
diana-deliu opened this issue Feb 19, 2024 · 3 comments
Open

Comments

@diana-deliu
Copy link

diana-deliu commented Feb 19, 2024

Hello!

The issue
I use spring cloud contract tests for a while now and they were working as expected. I've recently had to change my laptop (old one - Windows, this one Windows as well) and now the spring cloud contract tests are not generated anymore. We use Gradle as build tool.

What we've tried so far

  • generating them from the IDE as well as from PowerShell -> same error.
    .\gradlew.bat :contract-tests:generateContractTests --debug --rerun-tasks

  • manually compiling contract providing the full classpath and JDK -> the compilation is successful.
    javac -cp "C:\Users\diadeliu\.gradle\.tmp\gradle-javaexec-classpath3162018629030617727.jar;C:\Program Files\Java\jdk-11\lib\jrt-fs.jar" C:\Users\diadeliu\IdeaProjects\repo\contract-tests\build\stubs\META-INF\com.company\contract-tests\0.0.0\contracts\producer_name\consumer_name\SampleContract.java

  • providing gradle_home via environment variable or the folder path directly, in gradlew.bat and gradlew.sh files -> same error
    "-Dgradle.user.home=C:\Gradle" or
    "-Dgradle.user.home=gradle_home" where gradle_home is
    image

  • locally installing gradle version 8.6 and make IDE use it -> same error

  • I've had this issue before and it was because I have had a space in the path of my folder structure "Name Surname", but now that's not the case anymore, as per the provided path above.

Please keep in mind that the provided configuration works for almost all of my peers and it's been working for me as well for the last couple of years.
We use:

  • JDK 11.0.21
  • spring-cloud-dependencies 2021.0.3
  • spring-boot 2.6.11
  • org.springframework.cloud.contract 3.1.4
  • Gradle wrapper version 7.5

The actual error

java.lang.IllegalStateException: Exceptions occurred while trying to compile the file [==========
import org.springframework.cloud.contract.spec.Contract;
                                              ^^^^^^^^^
ERROR:package org.springframework.cloud.contract.spec does not exist
==========
, ==========
import org.springframework.cloud.contract.spec.internal.QueryParameters;
                                                       ^^^^^^^^^^^^^^^^
ERROR:package org.springframework.cloud.contract.spec.internal does not exist
==========
, ==========
import org.springframework.cloud.contract.spec.internal.RegexPatterns;
                                                       ^^^^^^^^^^^^^^
ERROR:package org.springframework.cloud.contract.spec.internal does not exist
==========
, ==========
import org.springframework.cloud.contract.spec.internal.Request;
                                                       ^^^^^^^^
ERROR:package org.springframework.cloud.contract.spec.internal does not exist
==========
, ==========
import org.springframework.cloud.contract.spec.internal.Response;
                                                       ^^^^^^^^^
ERROR:package org.springframework.cloud.contract.spec.internal does not exist
==========
, ==========
import org.springframework.cloud.contract.verifier.util.ContractVerifierUtil;
                                                       ^^^^^^^^^^^^^^^^^^^^^
ERROR:package org.springframework.cloud.contract.verifier.util does not exist
==========
, ==========
import static org.assertj.core.util.Lists.newArrayList;
                                   ^^^^^^
ERROR:package org.assertj.core.util does not exist
==========
, ==========
import static org.assertj.core.util.Lists.newArrayList;

We've run out of ideas, so any help is much appreciated. Thanks in advance!

@hackus
Copy link

hackus commented Feb 22, 2024

If it may help:

It works if downgrading to gradle-6.8-all
and using
id "org.springframework.cloud.contract" version "2.2.4.RELEASE"

@marcingrzejszczak
Copy link
Contributor

@shanman190 any ideas what can cause this? Gradle + windows ?

@shanman190
Copy link
Contributor

shanman190 commented May 6, 2024

@marcingrzejszczak, I don't think that it's a Windows + Gradle sort of problem.

Here's the steps that I'd go through:

  1. Where are the tests located? src/test/resources/contracts/? src/contractTest/resources/contracts/?

  2. Verify the dependencies by their configuration (test=testCompileClasspath, contractTest=contractTestCompileClasspath) with gradlew dependencyInsight --configuration <configuration> --dependency spring-cloud-contract-spec-java since it's failing to compile and the Contract class comes from that jar (repeat for other classes locations).

  3. If Gradle is showing the jars are resolving from a dependency standpoint, I'd go into the Gradle user home and verify it's contents of those jars by looking specifically for the classes that are failing to resolve inside of them.

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

5 participants