question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make CI/CD integration of Maven Plugin easier

See original GitHub issue

Issue

The Pact Maven Plugin currently requires that the service, that the providers should be verified against, is available prior to starting the maven build/goal. However, when you want to verify a new version on a build pipeline, you (usually) do not have an instance of that version which you can test against; it must be started right there and then.

This is hindered by the current implementation of the Maven Plugin, because

  1. the needed infrastructure (so the service itself and everything that it needs) cannot be started with just the Pact Maven Plugin
  2. the Pact Maven Plugin does not (easily) allow for setting the values for the host/port of a service provider dynamically

This issue is linked to this Slack Thread.

Expected behavior

The Pact Maven Plugins allows for easier integration of the necessary infrastructure (like the Gradle plugin).

Solutions

Possible solutions

IMO This issue can be fixed in three ways

  1. Add the ability to startup the necessary infrastructure to validate a provider (e.g. starting up testcontainers)
  2. Add the ability to dynamically set the provider host/port
  3. Do not fix; recommend the workaround (or something similar)

My current workaround

I’m starting the required infrastructure via the exec-maven-plugin as testcontainers and make the dynamic host/port available as system properties. Then I add a requestFilter to each provider that uses the REQUEST_RESPONSE verification type (i.e. REST APIs), where the request uri is changed to the previously set values. Both the infrastructure startup and the pact provider verification are done in the maven phase post-integration-test.

This here is the crucial part for the workaround:

<build>
    <plugins>
        <!-- Startup infrastructure for Pact REST provider tests -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>startup-pact-infrastructure</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <classpathScope>test</classpathScope>
                        <cleanupDaemonThreads>false</cleanupDaemonThreads>
                        <mainClass>com.example.pact.PrePactProviderVerificationSetup</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>au.com.dius.pact.provider</groupId>
            <artifactId>maven</artifactId>
            <configuration>
                <!-- pact config -->
                <serviceProviders>
                    <serviceProvider>
                        <name>MyProvider</name>
                        <protocol>http</protocol>
                        <requestFilter>
                            def host = System.properties['test.service.host'] ?: 'localhost'
                            def port = System.properties['test.service.port'] ?: '8080'
                            def path = request.getURI().getPath()
                            def query = request.getURI().getQuery()
        
                            request.setURI(URI.create("http://$host:$port$path" + (query ? "?$query" : '')))
                        </requestFilter>
                    </serviceProvider>
                </serviceProviders>
            </configuration>
            <executions>
                <!-- Publish contracts after Unit tests -->
                <execution>
                    <id>publish-pact-contracts</id>
                    <phase>test</phase>
                    <goals>
                        <goal>publish</goal>
                    </goals>
                </execution>
                <!-- Verify providers after integration tests -->
                <execution>
                    <id>verify-pact-contracts</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
uglyogcommented, Aug 29, 2021

You can now use

    <host>{{pact.host}}</host>
    <port>{{pact.port}}</port>

and that will look for the JVM system properties pact.host and pact.port when the verify task is run

0reactions
uglyogcommented, Sep 4, 2021

4.2.11 released

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apache Maven & Continuous Delivery/Deployment - CloudBees
To make this easier I have created a Maven Plugin to assist and a sample Git repository with a project set-up to work...
Read more >
Continuous Integration with Maven, Jenkins,Git & GitHub part-1
Topic : 1. Continuous Integration with Maven 2. Jenkins3. Git & GitHub #git #github #jenkins ...
Read more >
CI/CD for Java Maven using GitHub Actions - Medium
This tutorial will show you how to set up a CI/CD solution for a Java Maven project. The tutorial will start of with...
Read more >
CI/CD Pipeline Using Jenkins, Git and Maven - Appfleet
To install Maven plugins. Go to Dashboard > Manage Jenkins > Manage Plugins > Available and search for Maven, as shown below: On...
Read more >
Maven CI Friendly Versions
Maven CI Friendly Versions. Starting with Maven 3.5.0-beta-1 you can use the ${revision} , ${sha1} and/or ${changelist} as placeholders for the version in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found