This function makes sure the transitive dependencies for a maven artifact are available locally in the .m2 maven cache and calculates a local classpath which can be provided to rJava. The artifact may be specified either as a set of maven coordinates (in which case the artifact itself is also downloaded, and included in the classpath) or as a path to a jar file containing a pom.xml (e.g. a compiled jar file, a compiled ...-jar-with-dependencies, or a assembled ...-src.jar).

resolve_dependencies(
  groupId = NULL,
  artifactId = NULL,
  version = NULL,
  ...,
  coordinates = NULL,
  artifact = NULL,
  path = NULL,
  include_self = NULL,
  nocache = FALSE,
  verbose = c("normal", "quiet", "debug")
)

Arguments

groupId

the maven groupId, optional

artifactId

the maven artifactId, optional

version

the maven version, optional

...

passed on to as.coordinates()

coordinates

the maven coordinates, optional (either groupId,artifactId and 'version' must be specified, or 'coordinates', or 'artifact')

artifact

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

path

the path to the source directory, pom file or jar file. if not given rmaven will get the artifact from the maven central repositories

include_self

do you want include this path in the classpath. optional, if missing the path will be included if it is a regular jar, or a fat jar, otherwise not.

nocache

do not used cached version, by default we use a cached version of the classpath unless the pom.xml is newer that the cached classpath.

verbose

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

Value

a character vector of the classpath jar files (including the current one if appropriate)

Examples

# \donttest{
# This code can take quite a while to run as has
# to download a lot of plugins, especially on first run

# classpath would be cached if possible
resolve_dependencies(groupId = "commons-io", artifactId = "commons-io",
  version="2.11.0")
#> Updating Java dependencies, please be patient.
#> [INFO] Scanning for projects...
#> [INFO]                                                                         
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Building Apache Commons IO 2.11.0
#> [INFO] ------------------------------------------------------------------------
#> [INFO] 
#> [INFO] --- maven-dependency-plugin:3.1.1:build-classpath (default-cli) @ commons-io ---
#> [INFO] No dependencies found.
#> [INFO] Wrote classpath file '/home/runner/.cache/rmaven/commons-io_commons-io_2.11.0/classpath.txt'.
#> [INFO] ------------------------------------------------------------------------
#> [INFO] BUILD SUCCESS
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Total time: 3.405 s
#> [INFO] Finished at: 2024-04-24T19:36:01+00:00
#> [INFO] Final Memory: 19M/67M
#> [INFO] ------------------------------------------------------------------------
#> [1] "/home/runner/.cache/rmaven/.m2/repository/commons-io/commons-io/2.11.0/commons-io-2.11.0.jar"

# forcing download and classpath calculation of an artifact
resolve_dependencies(artifact = "org.junit.jupiter:junit-jupiter-api:5.9.0",
  nocache=TRUE)
#> [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 org.junit.jupiter:junit-jupiter-api:jar:5.9.0 with transitive dependencies
#> [INFO] ------------------------------------------------------------------------
#> [INFO] BUILD SUCCESS
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Total time: 1.341 s
#> [INFO] Finished at: 2024-04-24T19:36:03+00:00
#> [INFO] Final Memory: 15M/60M
#> [INFO] ------------------------------------------------------------------------
#> Updating Java dependencies, please be patient.
#> [INFO] Scanning for projects...
#> [INFO]                                                                         
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Building JUnit Jupiter API 5.9.0
#> [INFO] ------------------------------------------------------------------------
#> [INFO] 
#> [INFO] --- maven-dependency-plugin:2.8:build-classpath (default-cli) @ junit-jupiter-api ---
#> [INFO] Wrote classpath file '/home/runner/.cache/rmaven/org.junit.jupiter_junit-jupiter-api_5.9.0/classpath.txt'.
#> [INFO] ------------------------------------------------------------------------
#> [INFO] BUILD SUCCESS
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Total time: 1.923 s
#> [INFO] Finished at: 2024-04-24T19:36:06+00:00
#> [INFO] Final Memory: 14M/54M
#> [INFO] ------------------------------------------------------------------------
#> [1] "/home/runner/.cache/rmaven/.m2/repository/org/junit/jupiter/junit-jupiter-api/5.9.0/junit-jupiter-api-5.9.0.jar"           
#> [2] "/home/runner/.cache/rmaven/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar"                            
#> [3] "/home/runner/.cache/rmaven/.m2/repository/org/junit/platform/junit-platform-commons/1.9.0/junit-platform-commons-1.9.0.jar"
#> [4] "/home/runner/.cache/rmaven/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar"                 

# find the test jar in this package and calculate its stated dependencies
resolve_dependencies(path=
  system.file("testdata/test-project-0.0.1-SNAPSHOT.jar",package="rmaven"))
#> Updating Java dependencies, please be patient.
#> [INFO] Scanning for projects...
#> [INFO]                                                                         
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Building test project 0.0.1-SNAPSHOT
#> [INFO] ------------------------------------------------------------------------
#> [INFO] 
#> [INFO] --- maven-dependency-plugin:2.8:build-classpath (default-cli) @ test-project ---
#> [INFO] Wrote classpath file '/home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT/classpath.txt'.
#> [INFO] ------------------------------------------------------------------------
#> [INFO] BUILD SUCCESS
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Total time: 0.763 s
#> [INFO] Finished at: 2024-04-24T19:36:08+00:00
#> [INFO] Final Memory: 11M/40M
#> [INFO] ------------------------------------------------------------------------
#> [1] "/home/runner/work/_temp/Library/rmaven/testdata/test-project-0.0.1-SNAPSHOT.jar"                         
#> [2] "/home/runner/.cache/rmaven/.m2/repository/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar"

# find the test source code jar in this package and calculate its stated
# dependencies
resolve_dependencies(path=
  system.file("testdata/test-project-0.0.1-SNAPSHOT-src.jar",
  package="rmaven")
)
#> Updating Java dependencies, please be patient.
#> [INFO] Scanning for projects...
#> [INFO]                                                                         
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Building test project 0.0.1-SNAPSHOT
#> [INFO] ------------------------------------------------------------------------
#> [INFO] 
#> [INFO] --- maven-dependency-plugin:2.8:build-classpath (default-cli) @ test-project ---
#> [INFO] Wrote classpath file '/home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT_jar_src/classpath.txt'.
#> [INFO] ------------------------------------------------------------------------
#> [INFO] BUILD SUCCESS
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Total time: 0.783 s
#> [INFO] Finished at: 2024-04-24T19:36:09+00:00
#> [INFO] Final Memory: 11M/44M
#> [INFO] ------------------------------------------------------------------------
#> [1] "/home/runner/.cache/rmaven/.m2/repository/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar"
# }