Compilation will package the Java source code in to a Jar file for further
use. It will resolve dependencies and optionally package them into a single
uber jar
(using maven assembly).
compile_jar(
path,
nocache = FALSE,
verbose = c("normal", "quiet", "debug"),
with_dependencies = FALSE,
...
)
the path to - either a java source code directory containing a
pom.xml
file, the pom.xml
file itself, or a ...-src.jar
assembled by
the maven assembly plugin,
normally compilation is only performed if the input has
changed. nocache
forces recompilation
how much output from maven, one of "normal", "quiet", "debug"
compile the Java code to a '...-jar-with-dependencies.jar' including transitive dependencies which may be easier to embed into R code as does not need a class path (however may be large if there are a lot of dependencies)
passed to execute_maven(...)
, e.g. could include settings
parameter
the path to the compiled 'jar' file. If this is a fat jar this can be
passed straight to rJava
, otherwise an additional
resolve_dependencies(...)
call is required
# \donttest{
# This code can take quite a while to run as has to
# download a lot of plugins, especially on first run
path = package_jars("rmaven","src")
compile_jar(path,nocache=TRUE)
#> Compiling Java library, please be patient.
#> [INFO] Scanning for projects...
#> [INFO]
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Building test project 0.0.1-SNAPSHOT
#> [INFO] ------------------------------------------------------------------------
#> [INFO]
#> [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-project ---
#> [INFO] Using 'UTF-8' encoding to copy filtered resources.
#> [INFO] Copying 0 resource
#> [INFO]
#> [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-project ---
#> [INFO] Changes detected - recompiling the module!
#> [INFO] Compiling 1 source file to /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT_jar_src/test-project-0.0.1-SNAPSHOT/target/classes
#> [INFO]
#> [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-project ---
#> [INFO] Using 'UTF-8' encoding to copy filtered resources.
#> [INFO] Copying 0 resource
#> [INFO]
#> [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-project ---
#> [INFO] Nothing to compile - all classes are up to date
#> [INFO]
#> [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test-project ---
#> [INFO] Using 'UTF-8' encoding to copy filtered resources.
#> [INFO] Copying 0 resource
#> [INFO]
#> [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-project ---
#> [INFO] Nothing to compile - all classes are up to date
#> [INFO]
#> [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ test-project ---
#> [INFO]
#> [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test-project ---
#> [INFO] Building jar: /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT_jar_src/test-project-0.0.1-SNAPSHOT/target/test-project-0.0.1-SNAPSHOT.jar
#> [INFO]
#> [INFO] --- maven-assembly-plugin:3.2.0:single (trigger-assembly) @ test-project ---
#> [INFO] Building jar: /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT_jar_src/test-project-0.0.1-SNAPSHOT/target/test-project-0.0.1-SNAPSHOT-jar-with-dependencies.jar
#> [INFO] Building jar: /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT_jar_src/test-project-0.0.1-SNAPSHOT/target/test-project-0.0.1-SNAPSHOT-src.jar
#> [INFO] ------------------------------------------------------------------------
#> [INFO] BUILD SUCCESS
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Total time: 4.489 s
#> [INFO] Finished at: 2024-04-24T19:35:40+00:00
#> [INFO] Final Memory: 18M/67M
#> [INFO] ------------------------------------------------------------------------
#> /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT_jar_src/test-project-0.0.1-SNAPSHOT/target/test-project-0.0.1-SNAPSHOT.jar
path2 = system.file("testdata/test-project",package = "rmaven")
compile_jar(path2,nocache=TRUE,with_dependencies=TRUE)
#> Compiling Java library, please be patient.
#> [INFO] Scanning for projects...
#> [INFO]
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Building test project 0.0.1-SNAPSHOT
#> [INFO] ------------------------------------------------------------------------
#> [INFO]
#> [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-project ---
#> [INFO] Using 'UTF-8' encoding to copy filtered resources.
#> [INFO] skip non existing resourceDirectory /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT/test-project-0.0.1-SNAPSHOT/src/main/resources
#> [INFO]
#> [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-project ---
#> [INFO] Changes detected - recompiling the module!
#> [INFO] Compiling 1 source file to /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT/test-project-0.0.1-SNAPSHOT/target/classes
#> [INFO]
#> [INFO] --- maven-assembly-plugin:3.2.0:single (default-cli) @ test-project ---
#> [INFO] Building jar: /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT/test-project-0.0.1-SNAPSHOT/target/test-project-0.0.1-SNAPSHOT-jar-with-dependencies.jar
#> [INFO] Building jar: /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT/test-project-0.0.1-SNAPSHOT/target/test-project-0.0.1-SNAPSHOT-src.jar
#> [INFO]
#> [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-project ---
#> [INFO] Using 'UTF-8' encoding to copy filtered resources.
#> [INFO] skip non existing resourceDirectory /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT/test-project-0.0.1-SNAPSHOT/src/main/resources
#> [INFO]
#> [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-project ---
#> [INFO] Nothing to compile - all classes are up to date
#> [INFO]
#> [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test-project ---
#> [INFO] Not copying test resources
#> [INFO]
#> [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-project ---
#> [INFO] Not compiling test sources
#> [INFO]
#> [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ test-project ---
#> [INFO] Tests are skipped.
#> [INFO]
#> [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test-project ---
#> [INFO] Building jar: /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT/test-project-0.0.1-SNAPSHOT/target/test-project-0.0.1-SNAPSHOT.jar
#> [INFO]
#> [INFO] --- maven-assembly-plugin:3.2.0:single (trigger-assembly) @ test-project ---
#> [INFO] Building jar: /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT/test-project-0.0.1-SNAPSHOT/target/test-project-0.0.1-SNAPSHOT-jar-with-dependencies.jar
#> [INFO] Building jar: /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT/test-project-0.0.1-SNAPSHOT/target/test-project-0.0.1-SNAPSHOT-src.jar
#> [INFO] ------------------------------------------------------------------------
#> [INFO] BUILD SUCCESS
#> [INFO] ------------------------------------------------------------------------
#> [INFO] Total time: 1.827 s
#> [INFO] Finished at: 2024-04-24T19:35:43+00:00
#> [INFO] Final Memory: 15M/60M
#> [INFO] ------------------------------------------------------------------------
#> /home/runner/.cache/rmaven/org.example_test-project_0.0.1-SNAPSHOT/test-project-0.0.1-SNAPSHOT/target/test-project-0.0.1-SNAPSHOT-jar-with-dependencies.jar
# }