Passing locations to tests

It is possible to query a number of locations

ivypot.repoDetails.root (1)
ivypot.repoDetails.rootUri (2)
ivypot.repoDetails.binariesRoot (3)
ivypot.repoDetails.getBinariesRootFor('nodejs') (4)
ivypot.repoDetails.groovyRepository (5)
ivypot.repoDetails.kotlinRepository (6)
1 The location of the off-line repository.
2 A URI to the location of the off-line repository.
3 The location under which binaries will be downloaded from binary repositories
4 The location under which binaries will be downloaded for a specific binary repository. The repository must be defined in the root ivypot.binaryRepositories block.
5 The location of a file that can be included in compatibility tests and which defines the off-line repository in the correct Groovy DSL syntax.
6 The location of a file that can be included in compatibility tests and which defines the off-line repository in the correct Kotlin DSL syntax.
All of the above return lazy-evaluated providers.

These providers are useful for passing down to tests. For example:

tasks.named('test', Test) {
  systemProperty (
    'NODEJS_REPO',
    ivypot.repoDetails.getBinariesRootFor('nodejs').get()
  )
}

In an attempt to be helpful, when Ivypot is applied to a single project or to the subprojects of a multi-project, it will add the following system properties to every task of type Test.

org.ysb33r.ivypot.repo.root.dir

Directory where off-line repository is located.

org.ysb33r.ivypot.repo.root.uri

File URI for the off-line IVY repository.

org.ysb33r.ivypot.repo.binary.root.dir

Top directory where binaries are stored.

org.ysb33r.ivypot.repo.binary.root.uri

File URI to the above location.

org.ysb33r.ivypot.repo.groovy.dsl.file

Location of the Groovy DSL repository file.

org.ysb33r.ivypot.repo.groovy.dsl.uri

File URI for Groovy DSL.

org.ysb33r.ivypot.repo.kotlin.dsl.file

Location of the Kotlin DSL repository file.

org.ysb33r.ivypot.repo.kotlin.dsl.uri

File URI for Kotlin DSL

This can then be used in a test and the following example Spock test will show.

ExampleSpec.groovy
class ExampleSpec extends Specification {
  public static final String REPO_FILE = System.getProperty(
    'org.ysb33r.ivypot.repo.groovy.dsl.file'
  ) (1)

  @TempDir
  File testProjectDir (2)

  void 'some test'() {
    setup:
    writeBuildFile()

    when:
    final result = GradleRunner.create()
            .withProjectDir(testProjectDir)
            .withArguments(['myTestTask'])
            .forwardOutput()
            .build()

   then:
   result.task(':myTestTask').outcome == SUCCESS
  }

  void writeBuildFile() {
    new File(testProjectDir,'build.gradle').text = """
    plugins {
      id 'my.plugin.under.test'
    }

    ${new File(REPO_FILE).text} (3)
    """.stripIndent()
  }
}
1 Location of the file.
2 Spock temporary directory.
3 Extract content.