ITV / scala-pact

A Scala implementation of CDC using the Pact standard
Other
107 stars 53 forks source link

Better support for multi-project builds #204

Closed solarmosaic-kflorence closed 3 years ago

solarmosaic-kflorence commented 3 years ago

I have an sbt project that contains multiple sub-projects. For example:

Even though I've only included the ScalaPactPlugin on one project and provided settings to one project (impl), it seems to be binding to every projects settings. So when I run sbt test I get a lot of duplicate output and error messages for projects I haven't configured. It looks like this:

*************************************
*************************************
*************************************
** ScalaPact: Squashing Pact Files **
** ScalaPact: Squashing Pact Files **
*************************************
*************************************
*************************************
** ScalaPact: Squashing Pact Files **
*************************************
*************************************
** ScalaPact: Squashing Pact Files **
*************************************
** ScalaPact: Squashing Pact Files **
*************************************
> 2 files found that could be Pact contracts
> 2 files found that could be Pact contracts
> 2 files found that could be Pact contracts
> 2 files found that could be Pact contracts
> 2 files found that could be Pact contracts
> - application_disclosure_5a5b9c726d2a3db22f7ae44227bc7ca405072e95_tmp.json
> - application_disclosure_46d999a991463c9d23dd5d7233805ab182e1b50d_tmp.json
> - application_disclosure_5a5b9c726d2a3db22f7ae44227bc7ca405072e95_tmp.json
> - application_disclosure_46d999a991463c9d23dd5d7233805ab182e1b50d_tmp.json
> - application_disclosure_5a5b9c726d2a3db22f7ae44227bc7ca405072e95_tmp.json
> - application_disclosure_46d999a991463c9d23dd5d7233805ab182e1b50d_tmp.json
> - application_disclosure_5a5b9c726d2a3db22f7ae44227bc7ca405072e95_tmp.json
> - application_disclosure_46d999a991463c9d23dd5d7233805ab182e1b50d_tmp.json
> - application_disclosure_5a5b9c726d2a3db22f7ae44227bc7ca405072e95_tmp.json
> - application_disclosure_46d999a991463c9d23dd5d7233805ab182e1b50d_tmp.json
> 1 pacts found:
> 1 pacts found:
> 1 pacts found:
> 1 pacts found:
> - application -> disclosure

> - application -> disclosure

> - application -> disclosure

> - application -> disclosure

> 0 errors
> 0 errors
> 0 errors
> 0 errors
> 1 pacts found:
> - application -> disclosure

> 0 errors
[success] Total time: 1 s, completed Dec 18, 2020 6:15:12 PM
*************************************
*************************************
*************************************
** ScalaPact: Publishing Contracts **
*************************************
*************************************
*************************************
** ScalaPact: Publishing Contracts **
*************************************
** ScalaPact: Publishing Contracts **
*************************************
** ScalaPact: Publishing Contracts **
** ScalaPact: Publishing Contracts **
*************************************
Snapshot pact file publishing not permitted
Snapshot pact file publishing not permitted
Snapshot pact file publishing not permitted
*************************************
Publishing of pact contracts against snapshot versions is not allowed by default.
Publishing of pact contracts against snapshot versions is not allowed by default.
Publishing of pact contracts against snapshot versions is not allowed by default.
Snapshot pact file publishing not permitted
Pact broker does not cope well with snapshot contracts.
Pact broker does not cope well with snapshot contracts.
Publishing of pact contracts against snapshot versions is not allowed by default.
Pact broker does not cope well with snapshot contracts.
Pact broker does not cope well with snapshot contracts.
To enable this feature, add "allowSnapshotPublish := true" to your pact.sbt file.
To enable this feature, add "allowSnapshotPublish := true" to your pact.sbt file.
To enable this feature, add "allowSnapshotPublish := true" to your pact.sbt file.
To enable this feature, add "allowSnapshotPublish := true" to your pact.sbt file.
cURL for request: curl -X PUT 'https://X.pactflow.io/pacticipants/application/versions/SNAPSHOT/tags/X' -H 'Content-Type: application/json' -H 'Authorization: <REDACTED>' -H 'Content-Length: 1076'
cURL for request: curl -X PUT 'https://X.pactflow.io/pacts/provider/disclosure/consumer/application/version/SNAPSHOT' -H 'Content-Type: application/json' -H 'Authorization: <REDACTED>' -H 'Content-Length: 1076'
Publishing 'application -> disclosure' (With tags: poc/pact/API-340) to:
 > https://X.pactflow.io/pacts/provider/disclosure/consumer/application/version/SNAPSHOT
Success

I would expect my settings to have only applied to the single project to which I applied them. I have also tried creating a configuration specifically for pact like so:

lazy val Pact = config("pact").extend(Test)

Attempting to configure pact to only run when I specify sbt pact:test -- but the settings also seem to bleed outside of this configuration.

solarmosaic-kflorence commented 3 years ago

This is also causing problems due to https://github.com/ITV/scala-pact/pull/149

solarmosaic-kflorence commented 3 years ago

As a workaround for now I can update my pipeline to only publish pact files for a specific project (e.g. sbt impl/pactPublish).

solarmosaic-kflorence commented 3 years ago

I think updating this line to noTrigger would at least make the pact settings only apply to the projects it is explicitly enabled on https://github.com/ITV/scala-pact/blob/master/sbt-scalapact/src/main/scala/com/itv/scalapact/plugin/ScalaPactPlugin.scala#L18

Currently it is being applied to every project regardless of whether or not .enablePlugins(ScalaPactPlugin) is defined

jbwheatley commented 3 years ago

@solarmosaic-kflorence does .disablePlugins(ScalaPactPlugin) in your sub-projects also give the desired effect?

solarmosaic-kflorence commented 3 years ago

@jbwheatley it does, but I think that is a much less desirable approach and also not what I expected given the documentation in the readme.

Another benefit of using noTrigger is that it is more flexible. For example, I want to limit the plugin to the Pact configuration in my project (so that all code would go into src/pact/scala and everything would be executed with sbt pact:X). Right now, I cannot eliminate the settings in the compile and test scope, so for example pactTest exists at both sbt pactTest and sbt pact:pactTest. Plus, I have to include my plugin and explicitly disable this plugin on all but one of my sub-projects.