How to fetch or resolve compile vs runtime vs test classpaths?
Apologies for what may be an obvious question, but I don't see the answer explicitly in the docs.
I'd like to use coursier to manage the dependencies for a java component in a larger, multi-language project. That project already has a build tool that I'd like to continuing using for the java component, which is why I'm not initially reaching for one of the jvm-native build tools. Additionally, apache ivy looks too unmaintained for me to trust easily. So from the outside coursier looks like a good fit.
There are a few features I'm looking for, which coursier fetch seems to satisfy:
- I can pass in a list of dependency constraints for my component in one or more files (
--dependency-file) - I can have it emit a lock file (
--json-output-file, with some post-processing) - I can have it emit classpaths... (
--classpath) - ...for various project phases (
--default-configuration...?)
It's this last point that I'm unsure of. In the bad old maven days we declared dependencies with "scopes" to control which jars were used at compile time, or run time, or test time (the "project phases" I mention above) since these classpaths often needed to be different. This isn't quite the same thing as having one set of dependencies per phase, since the scopes affect how transitive dependencies are managed.
I feel less confident in the --default-configuration option after seeing some odd results while experimenting with the tool. However this may also come down to not knowing how to tell coursier what scope my dependencies have.
To be concrete, here is an attempt to get a runtime classpath for a dependency set that includes gson at runtime, and junit-jupiter-api at test time:
$ coursier fetch --classpath --default-configuration runtime com.google.code.gson:gson:2.13.2 org.junit.jupiter:junit-jupiter-api:5.9.3:test | tr : '\n'
Downloading https://repo1.maven.org/maven2/org/junit/jupiter/junit-jupiter-api/5.9.3/junit-jupiter-api-5.9.3-tests.jar
Failed to download https://repo1.maven.org/maven2/org/junit/jupiter/junit-jupiter-api/5.9.3/junit-jupiter-api-5.9.3-tests.jar
Downloading https://repo1.maven.org/maven2/org/junit/jupiter/junit-jupiter-api/5.9.3/junit-jupiter-api-5.9.3-tests.jar.sha1
Failed to download https://repo1.maven.org/maven2/org/junit/jupiter/junit-jupiter-api/5.9.3/junit-jupiter-api-5.9.3-tests.jar.sha1
/build/coursier-cache/https/repo1.maven.org/maven2/com/google/code/gson/gson/2.13.2/gson-2.13.2.jar
/build/coursier-cache/https/repo1.maven.org/maven2/org/junit/jupiter/junit-jupiter-api/5.9.3/junit-jupiter-api-5.9.3.jar
/build/coursier-cache/https/repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.41.0/error_prone_annotations-2.41.0.jar
/build/coursier-cache/https/repo1.maven.org/maven2/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar
/build/coursier-cache/https/repo1.maven.org/maven2/org/junit/platform/junit-platform-commons/1.9.3/junit-platform-commons-1.9.3.jar
/build/coursier-cache/https/repo1.maven.org/maven2/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar
..we can see the junit jars still appearing. One explanation is the :test on the end of the junit dependency is not indicating a scope (coursier configuration?) in the sense that I am looking for but a "classifier" or something else.
How can I ask coursier to emit a compile classpath, vs a runtime classpath or a test classpath?