Hey there :wave: I’m having a bit of trouble getti...
# pact-jvm
j
Hey there 👋 I’m having a bit of trouble getting the
pactVerify
Gradle command to run for my message provider - it doesn’t seem to be able to find the methods I’ve annotated even though it should be on the test classpath I’ve commented out the
packagesToScan
section in my Gradle and it still can’t find it, it just gives me an error:
Copy code
No annotated methods were found for interaction 'message.interaction.name'. You need to provide a method annotated with @PactVerifyProvider("message.interaction.name") on the classpath that returns the message contents.
I have a method annotated correctly in my test directory (the test runs and passes if I run it using JUnit):
Copy code
@PactVerifyProvider("message.interaction.name")
public String verifyInteraction() {
    ...
}
My build.gradle currently looks like this:
Copy code
pact {
    broker {
        pactBrokerUrl = "$System.env.PACT_BROKER_BASE_URL"
        pactBrokerToken = "$System.env.PACT_BROKER_TOKEN"
    }

    serviceProviders {
        providerName {
            verificationType = 'ANNOTATED_METHOD'
            //  packagesToScan = ['*']
            hasPactsFromPactBroker("$System.env.PACT_BROKER_BASE_URL", authentication: ['Bearer', "$System.env.PACT_BROKER_TOKEN"])
        }
    }
}
If you’ve any suggestions on what I could try in order to sort this I’d really appreciate it - thanks 😄
t
You could set
packagesToScan
to tell it where your test is
What is your test class annotated with?
j
I tried that originally, then took it out as apparently that should scan the full classpath so thought it might have better success
My test class is annotated like this:
Copy code
@Provider("providerName")
@PactBroker(url = "url",
		authentication = @PactBrokerAuth(token = "token"))
public class ProviderMessageTest {
...
t
Hm. Looks right to me, but it has been a while since I worked with the JVM.
j
Thanks for checking, at least I don’t seem to be missing something obvious 👍
For what it’s worth I’m on version
4.3.19
, 4.4+ seems to give me an error due to my Gradle version (which is currently locked for the project I’m working on)
Though just for peace of mind, I tried bumping it to
4.5.3
locally and still get the same error
u
What is the package that
ProviderMessageTest
is in? That is what you should set
packagesToScan
to. Where does this test class sit, is it in another module? What JDK are you using?
j
I’m fairly new to Gradle so apologies if my answers aren’t exactly what you’re looking for The repo I’m working with has two projects inside (
provider_service
and
provider_service_api
, the service is the provider), each with their own
build.gradle
, the Gradle snippet I shared is from the repo’s root
build.gradle
Its package is
com.company.providername.pact
, which is what I had originally set it to The test file is in
provider_service/src/test/unit/java/com/company/providername/pact/
My JDK seems to be set to 17
u
Ok, that will explain why the class is not found. You need to add the
provider_service
to the build classpath of the root Gradle project. When the Gradle plugin runs, it uses the build classpath to load classes, not the project compile or test classpaths.
I would recommend using JUnit to run the test, because the classes will all be available
j
Ok cool thanks for that 😄 I’ll try and update the Gradle then see if I can get it working I was originally using JUnit but it seemed to require adding the broker auth token to every test class (which we’d like to keep secured), and I wasn’t having any luck getting it to pick up system properties I’ll try again as it definitely worked though