This can be used to get a JAR file from the maven repositories into a local .m2 repository. The local path is made available for importing it into the rJava classpath for example.

fetch_artifact(
  groupId = NULL,
  artifactId = NULL,
  version = NULL,
  ...,
  coordinates = NULL,
  artifact = NULL,
  repoUrl = .default_repos(),
  nocache = FALSE,
  verbose = c("normal", "quiet", "debug")
)

Arguments

groupId

optional, the maven groupId,

artifactId

optional, the maven artifactId,

version

optional, the maven version,

...

other maven coordinates such as classifier or packaging

coordinates

optional, but if not supplied groupId and artifactId must be, coordinates as a coordinates object (see as.coordinates())

artifact

optional, coordinates as an artifact string groupId:artifactId:version[:packaging[:classifier]] string

repoUrl

the URLs of the repositories to check (defaults to Maven central, 'Sonatype' snapshots and 'jitpack', defined in options("rmaven.default_repos"))

nocache

normally artifacts are only fetched if required, nocache forces fetching

verbose

how much output from maven, one of "normal", "quiet", "debug"

Value

the path of the artifact within the local maven cache

Examples

# \donttest{
# This code can take quite a while to run as has to
# download a lot of plugins, especially on first run
fetch_artifact(artifact="com.google.guava:guava:31.1-jre")
#> [INFO] Scanning for projects...
#> [INFO]                                                                         
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Building Maven Stub Project (No POM) 1
#> [INFO] ------------------------------------------------------------------------
#> [INFO] 
#> [INFO] --- maven-dependency-plugin:3.3.0:get (default-cli) @ standalone-pom ---
#> [INFO] Resolving com.google.guava:guava:jar:31.1-jre with transitive dependencies
#> [INFO] ------------------------------------------------------------------------
#> [INFO] BUILD SUCCESS
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Total time: 1.513 s
#> [INFO] Finished at: 2024-04-24T19:35:56+00:00
#> [INFO] Final Memory: 15M/57M
#> [INFO] ------------------------------------------------------------------------
#> /home/runner/.cache/rmaven/.m2/repository/com/google/guava/guava/31.1-jre/guava-31.1-jre.jar
fetch_artifact(coordinates = as.coordinates("org.junit.jupiter",
  "junit-jupiter-api","5.9.0"))
#> /home/runner/.cache/rmaven/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.9.0/junit-jupiter-api-5.9.0.jar
# }