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

pact-jvm-junit5 writes all pacts to target/pacts instead of $buildDir/pacts #690

Closed
steam0 opened this issue May 31, 2018 · 14 comments
Closed

Comments

@steam0
Copy link

steam0 commented May 31, 2018

The title explains it.

Here is my build.gradle file for reference

buildscript {
	ext {
		springBootVersion = '2.0.2.RELEASE'
		pactDirectory = "$buildDir/pacts"
	}
	repositories {
		mavenCentral()
	}
	dependencies {
		classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
		classpath("org.junit.platform:junit-platform-gradle-plugin:1.1.0")
		classpath("au.com.dius:pact-jvm-provider-gradle_2.12:3.5.16")
	}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'au.com.dius.pact'
apply plugin: 'org.junit.platform.gradle.plugin'

group = 'io.redacted'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
	mavenCentral()
}


dependencies {
	compile("org.projectlombok:lombok:1.16.16")
	compile('org.springframework.boot:spring-boot-starter-web')
	testCompile('org.springframework.boot:spring-boot-starter-test')
	testCompile('au.com.dius:pact-jvm-consumer-junit5_2.12:3.5.16')
	testRuntime("org.junit.jupiter:junit-jupiter-engine:5.1.0")
	testRuntime("org.junit.platform:junit-platform-launcher:1.1.0")
}

task wrapper(type: Wrapper) {
	gradleVersion = '4.6'
}

// Set where to put pact files
test {
	systemProperties['pact.rootDir'] = pactDirectory
}

// Publish pact files
pact {
	publish {
		pactDirectory = pactDirectory
		pactBrokerUrl = 'http://localhost:3000'
	}
}

// Push pacts to broker
build.finalizedBy(pactPublish)
@uglyog
Copy link
Member

uglyog commented Jun 2, 2018

I just ran ArticlesTest from the pact-jvm project and it definitely writes the pacts to the correct directory, it must be your setup that has an issue.

13:33:00.217 [Test worker] DEBUG au.com.dius.pact.consumer.junit5.PactConsumerTestExt - Writing pact ArticlesConsumer -> ArticlesProvider to file /home/ronald/Development/Projects/Pact/pact-jvm/pact-jvm-consumer-junit5/build/2.12/pacts/ArticlesConsumer-ArticlesProvider.json
au.com.dius.pact.consumer.junit5.ArticlesTest > testArticles(MockServer) PASSED

try this

    test {
      useJUnitPlatform()
      systemProperty 'pact.rootDir', "$buildDir/pacts"
    }

@dervism
Copy link

dervism commented Jun 10, 2018

I have to following two lines that are working for me:

def pactFolderString = "$buildDir" + File.separator + "pacts"
test.systemProperties["pact.rootDir"] = pactFolderString

@Maragues
Copy link

Maragues commented Feb 7, 2019

I'm having the same issue running 3.6.1 on JUnit 4 (Android project)

I've tried your suggestions without luck

@Maragues
Copy link

Maragues commented Apr 2, 2019

For some reason PactConsumerConfig doesn't detect that it's running inside gradle. Maybe Android doesn't set System.getenv("org.gradle.test.worker").

That said, I've been able to overwrite the pactDirectory by extending from ConsumerPactTestMk2 and modifying PactTestExecutionContext on each test run. This is my PactBaseTest

 @CallSuper
 override fun runTest(mockServer: MockServer, context: PactTestExecutionContext) {
     context.pactFolder = PACT_FOLDER
 }

@uglyog
Copy link
Member

uglyog commented Apr 13, 2019

@Maragues it is not Android, I have noticed this with my builds. Something has changed with an upgrade to Gradle.

@uglyog
Copy link
Member

uglyog commented Apr 13, 2019

@Maragues looks like org.gradle.test.worker is now set as a system property. I've updated the code to check for both.

@uglyog
Copy link
Member

uglyog commented Apr 14, 2019

This fix has been released with version 3.6.4

@uglyog uglyog closed this as completed Apr 14, 2019
@steam0
Copy link
Author

steam0 commented Apr 14, 2019

Thank you Ronald! Great work as always! :)

@HaMatthias
Copy link

Still facing the issue that version 3.6.7 is writing my generated pacts to 'target/pacts' instead of '$buildDir/pacts'.

And the publish tasks default directory for hooking the pacts is in the "$buildDir/pacts"

I am running on gradle 5.3.1

Any ideas ?

@uglyog
Copy link
Member

uglyog commented Jun 1, 2019

@HaMatthias have a look at https://github.com/uglyog/pact-junit5-test and compare it with your project. That project writes the pact files to build/pacts

@kekko1212
Copy link

Hey @HaMatthias and @uglyog, I had the same issue where the pact files are actually stored in the target dir by default.

I noticed that it actually happens only when I run my pact tests using IntelliJ. If instead I run the same tests from CLI, it works correctly.

The issue is that I was running the tests using IntelliJ IDEA instead of Gradle (Default) as per screenshot (Settings > Build, Execution, Deployment > Build and Tools > Gradle)
image

Changing it to Gradle worked for me.

@uglyog
Copy link
Member

uglyog commented May 21, 2020

@kekko1212 when running from IntelliJ you'll need to set the pact.rootDir property to where you want the pacts written to.

@KANISHKART
Copy link

@uglyog I am trying to change pact directory in JVM and it is not writting in my specified directory it always write in target/pacts

@HaMatthias
Copy link

HaMatthias commented Jul 1, 2020

Hey @HaMatthias and @uglyog, I had the same issue where the pact files are actually stored in the target dir by default.

I noticed that it actually happens only when I run my pact tests using IntelliJ. If instead I run the same tests from CLI, it works correctly.

The issue is that I was running the tests using IntelliJ IDEA instead of Gradle (Default) as per screenshot (Settings > Build, Execution, Deployment > Build and Tools > Gradle)
image

Changing it to Gradle worked for me.

Yep, that was my problem. Problem solved for me! I preferably use IntelliJ test runner, so i added property to the test run config

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

No branches or pull requests

7 participants