Source Sets

How Elide finds a project's sources, resources and per-set classpaths.

A source set is a named group of sources and resources. Elide derives compile, test and packaging tasks from them.

Conventional layout

main is in src/main, test in src/test, any other set in src/<name>:

PathMeaning
src/<set>/java, /kotlin, /js, /ts, /pythonSources, one directory per language
src/<set>/resourcesResources
  • Every language directory that exists is compiled. With none, src/<set> itself is the source root.
  • src is used as src/main; test or tests as src/test.
  • main and test exist when their directories do. Other sets must be declared.

This layout needs no sources block:

src/main/kotlin/sample/Main.kt
src/main/resources/app.properties
src/test/kotlin/sample/MainTest.kt

elide project info prints the resolved sets; (by convention) marks paths from the layout.

Declaring source sets

sources {
  // A glob, for a set that only moves its sources.
  ["main"] = "lib/**/*.kt"

  // An entry with more to say.
  ["integrationTest"] {
    type = "test"
    paths { "it/**/*.kt" }
  }
}

new Sources.SourceSetSpec { … } (with import "elide:Sources.pkl" as Sources) is the long form of the entry. Paths are project-relative globs or directories; a directory is walked recursively.

Precedence

Each declared property replaces the convention for that property only.

PropertyLeft outDeclared
typeInferred from the nameAlways used
pathsThe conventional layout for the nameUsed verbatim
resourcessrc/<name>/resources, when presentUsed verbatim
dependsOnTest and example sets see mainUsed verbatim; empty means nothing
typeInferred fromBehavior
testtest, testsRun by elide test; resolves testPackages.
exampleexample, examplesProduction set.
sourceany other nameProduction set.
other—Production set.

Production sets are packaged by artifacts that name no sources. A declared set whose paths cover src/main or src/test replaces that conventional set, so files never compile twice.

Dependencies and classpaths

Production sets resolve packages, modules, compileOnly, runtimeOnly and processors. Test sets add testPackages and the set they depend on. See Dependencies.

elide classpath                 # main:compile
elide classpath runtime         # main:runtime
elide classpath test:runtime    # [<source-set>:]<usage>

Prints the classpath from the last elide install, one entry per line. Usages: compile, runtime, processor, modules, toolchain, provided; anything else is a usage error. Install also writes .dev/dependencies/m2/{compile,runtime,test,processors}.classpath.

Resources

On the JVM, resources are on the classpath for runs and tests and are copied into JARs.

sources {
  ["main"] {
    resources {
      "assets/banner.txt"
      new {
        from = "config/services"
        into = "META-INF"
      }
    }
  }
}

A plain path is copied to the output root. from (a directory or file) is copied under into: config/services/app.Service becomes META-INF/services/app.Service. into defaults to the root.

Artifacts

artifacts {
  ["app"] = new Jvm.Jar {}                 // every non-test source set
  ["lib"] = new Jvm.Jar { sources { "api" } }
}

Source and Javadoc JARs follow the same rule. A JAR’s resources add to its sets’. See JAR Assembly.

Languages

The file extension determines the language: .java, .kt/.kts, .js/.mjs/.cjs/.jsx, .ts/.mts/.cts/.tsx, .py. A set with Java and Kotlin runs both compilers; a set with neither runs no JVM compilation.