JavaRuntimeSpec class

A package's Java runtime: the jars it needs, where they are cached, and how to check that a set of jars is the right one.

A package that calls into Java libraries has to get their jars onto the machine somehow. The approach here: Maven resolves them once, at build time, from a POM the package ships, into a versioned cache directory — and from then on that directory is the deployable artifact. No Maven at runtime, no network, and a dart compile exe binary works as long as the directory is there.

const reportsRuntime = JavaRuntimeSpec(
  name: 'my_reports',
  runtimeId: 'v1-jasper6.21.0',
  pomPackageFile: 'tool/runtime_pom.xml',
  cacheDirEnv: 'MY_REPORTS_JAVA_CACHE',
  classPathEnv: 'MY_REPORTS_JAVA_CLASSPATH',
  setupCommand: 'dart run my_reports:setup_jars',
  requiredClasses: {
    'net.sf.jasperreports.engine.JasperCompileManager': 'jasperreports',
  },
  forbiddenClasses: {'jakarta.xml.bind.JAXBContext': 'jakarta.xml.bind-api'},
);

The cache is laid out as <base>/<runtimeId>/:

pom.xml          the POM, copied from the package
jars/            what Maven resolved
classpath.txt    one jar per line, relative to this directory
manifest.json    the runtime id, the jars and their sizes

Relative paths make the directory relocatable — it can be copied into a container image as is — and the runtime id in the path means a new set of jars gets a new directory instead of overwriting the one a running deployment uses.

Constructors

JavaRuntimeSpec({required String name, required String runtimeId, String pomPackageFile = 'tool/pom.xml', String? cacheDirEnv, String? classPathEnv, String? setupCommand, Map<String, String> requiredClasses = const {}, List<String> requiredResources = const [], Map<String, String> requiredResourceContent = const {}, Map<String, String> forbiddenClasses = const {}, String? loggingProperties, Map<String, Object?> manifestExtras = const {}})
const

Properties

cacheDirEnv → String?
An environment variable that overrides the cache's base directory, for a deployment that keeps the cache elsewhere.
final
classPathEnv → String?
An environment variable that gives the class path outright — a list separated by classPathSeparator, or the path of a file with one entry per line. The way out for a deployment that resolves jars without Maven.
final
forbiddenClasses → Map<String, String>
Class name → what brings it in. None may be in the jars: for the libraries that conflict with one the runtime depends on.
final
hashCode → int
The hash code for this object.
no setterinherited
loggingProperties → String?
A java.util.logging configuration written next to the jars at provisioning, as logging.properties, when not null.
final
manifestExtras → Map<String, Object?>
More entries for manifest.json — library versions, say.
final
name → String
The Dart package this runtime belongs to — its directory name in the cache, and where pomPackageFile is looked up.
final
pomPackageFile → String
The POM, as a path relative to the package root (not lib/: a POM is usually in tool/).
final
requiredClasses → Map<String, String>
Class name → what should provide it. Each must be in the jars.
final
requiredResourceContent → Map<String, String>
Resource path → text that at least one copy of it must contain.
final
requiredResources → List<String>
Resource paths (META-INF/services/…) that must be in the jars.
final
runtimeId → String
Which set of jars this is. Change it whenever the POM changes in a way that matters: it names the cache directory, and a cache with another id is ignored.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
setupCommand → String?
The command that provisions the runtime, for error messages.
final

Methods

cacheBaseDir({String? override, Map<String, String>? environment}) → Directory
The cache's base directory, absolute: override, then cacheDirEnv, then the operating system's cache directory for name.
defaultCacheBasePath({Map<String, String>? environment}) → String
The operating system's cache directory for name: ~/Library/Caches on macOS, %LOCALAPPDATA% on Windows, $XDG_CACHE_HOME or ~/.cache elsewhere. With no home directory in the environment — some service accounts — it falls back to the current directory; set cacheDirEnv or pass an override there instead.
devRuntimeDir({String? projectDir}) → Directory?
.dart_tool/<name>/<runtimeId> under projectDir (the current directory by default), or null when there is no .dart_tool.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
runtimeDir({String? override, Map<String, String>? environment}) → Directory
<cacheBaseDir>/<runtimeId>.
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Constants

classPathFileName → const String
classpath.txt.
jarsDirName → const String
jars.
loggingPropertiesFileName → const String
logging.properties.
manifestFileName → const String
manifest.json.