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 file output folders differ between SBT and tests for sub-projects #212

Open
solarmosaic-kflorence opened this issue Jan 20, 2021 · 4 comments

Comments

@solarmosaic-kflorence
Copy link
Contributor

Currently ScalaPactEnv sets outputPath to None by default:

In various places, a default value of "target/pacts" is then assigned. For example:

val giveOutputPath: String = outputPath.getOrElse(Properties.envOrElse("pact.rootDir", "target/pacts"))

This results in the project root target/pacts folder being used by default, even for sub-projects. This means by default, pact commands will fail on sub-projects. I would suggest instead, we use a default of (target.value / "pacts").getPath as provided by SBT, for example:

scalaPactEnv := ScalaPactEnv.empty.withOutputPath((target.value / "pacts").getPath),

This way the default target path will work on sub-projects by default. This means we should probably also update the logic so that other places in the code will expect the outputPath to always be defined and used as a fallback to Properties.envOrElse("pact.rootDir") so that defining the system override will still take precedence.

@solarmosaic-kflorence
Copy link
Contributor Author

solarmosaic-kflorence commented Jan 21, 2021

As a side note, when running tests in a sub-project the files are already written to the correct place (sub-project target/pacts by default).

EDIT: actually, when I run the tests inside of intelliJ they seem to write to the root project target/pacts folder, but when I run them from the command line they write to the project target/pacts folder...

@solarmosaic-kflorence solarmosaic-kflorence changed the title ScalaPactEnv should use project target folders by default Pact file output folders differ between SBT and tests for sub-projects Jan 21, 2021
@solarmosaic-kflorence
Copy link
Contributor Author

I guess I'm less concerned about the default path, as long as it is consistent for both tests and SBT tasks. To clarify I am currently seeing the following behavior:

  • when sbt test is run from command line, pact files are output to the sub-project/target/pacts directory
  • when the same tests are run from within IntelliJ, pact files are output to the root project target/pacts directory
  • when SBT tasks like sbt pactPack are run, they are currently always looking in the root project target/pacts directory

So it seems like the current oddball is the output location of sub-project tests. Strangely, when I debug the code, file.getAbsolutePath points to the root project target/pacts directory, but when file.createNewFile() is called, it creates the file in sub-project/target/pacts... must have something to do with the workspace Java is using.

@solarmosaic-kflorence
Copy link
Contributor Author

Oddly enough, this works:

  val file1 = new File("target/pacts")
  println(file1.getAbsolutePath)
  val file2 = new File(file1.getAbsolutePath + "/" + UUID.randomUUID())
  file2.createNewFile()
  println(file2.getAbsolutePath)

I think updating

To use an absolute path instead of a relative path will fix the issue.

@solarmosaic-kflorence
Copy link
Contributor Author

For now I can use this workaround with ScalaPactForgerDsl:

  implicit override val options: ScalaPactOptions = ScalaPactOptions(
    writePactFiles = true,
    outputPath = new File("target/pacts").getAbsolutePath
  )

Will open a PR for this tomorrow.

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

1 participant