SBT plugin for building installers with install4j, the multi-platform installer builder.
sbt-install4j is available for sbt 1.9 or newer and for sbt 2 (sbt 2 requires JDK 17 or newer).
For older sbt 1.x use sbt-install4j 1.5.0.
Import sbt-install4j plugin to use install4j task.
addSbtPlugin("com.github.jpsacha" % "sbt-install4j" % "1.7.0")Sample use: add the following to your build.sbt:
enablePlugins(SBTInstall4J)
install4jProjectFile := "installer/example.install4j"In sbt 1 also add:
exportJars := trueThis packages classes of your project, and of projects it depends on, into JARs that are copied to the installer.
Without it your project's classes are not copied, only JARs of library dependencies.
In sbt 2 exportJars is true by default.
SBT tasks provided by sbt-install4j plugin:
-
install4j: Task - Builds Install4J project. Simple usage from SBT REPLsbt> install4jIt will build project defined by setting
install4jProjectFile. Before running the compiler, it packages the project (Compile / packageBin) and runsinstall4jCopyDependedJars. The task fails if the install4j compiler exits with an error.It can take optional arguments that are passed to the Install4J compiler. Refer to
install4jcdocumentation in install4j Help for list of supported command line options. You can print option summary from SBT REPL usingsbt> install4j --helpExample of only building
windowsmedia typesbt> install4j -m windows -
install4jCopyDependedJars: Task - Copies project dependencies to directoryinstall4jDependedJarsDir. Jars copied by a previous run that are no longer dependencies are removed. Other files in that directory are not touched. To be safe, runcleanbefore building a release. It removes all copied jars wheninstall4jDependedJarsDiris undertarget(the default).
SBT settings provided by sbt-install4j plugin:
-
install4jCopyDependedJarsExclusions: Seq[String] - List of regex expressions that match files that will be excluded from copying. -
install4jCopyDependedJarsEnabled: Boolean - iftruedependent jars will be copied, iffalsethey will be not. -
install4jcFile: File - Location of the install4j's command line compilerinstall4jc[.exe]. It can be found in thebindirectory of the install4j installation. Default can be set with environment variableINSTALL4JC_FILE.install4jcFile := file("C:/Program Files/install4j13/bin/install4jc.exe")
-
install4jProjectFile: String - Relative path to the install4j project file that should be built. Default isinstaller/installer.install4j. -
install4jDependedJarsDir: String - Location where dependent jars will be copied. Relative path is resolved against the project base directory. Default islibincrossTarget, for instance,target/scala-2.13/libin sbt 1 ortarget/out/jvm/scala-3.3.8/my-project/libin sbt 2. Setting a fixed location makes it easier to reference from the install4j project, and keeps it the same between sbt versions and when the Scala version changes, for instance:install4jDependedJarsDir := "target/install4j-lib"
-
install4jExtraOptions: Seq[String] - Additional command line options passed to the compiler. -
install4jVerbose: Boolean - Enables verbose mode. -
install4jRelease: String - Override the application version. Version number components can be alphanumeric and should be separated by dots, dashes or underscores. -
install4jCompilerVariables: Map[String, String] - Override a compiler variable with a different value. In the map, thekeyis variable's name, thevalueis variable's value. -
install4jHomeDir: File - Deprecated. install4j installation directory. It assumes that install4j compiler is in subdirectorybin. Default can be set with environment variable or system propertyINSTALL4J_HOME. This option is deprecated, use environment variableINSTALL4JC_FILEor settinginstall4jcFileinstead.
The sbt-install4j executes install4j compiler.
It needs to know its location.
It attempts to determine the location based on the OS used.
On Windows it is assumed to be:
C:\Program Files\install4j13\bin\install4jc.exe
On macOS:
/Applications/install4j.app/Contents/Resources/app/bin/install4jc
On Linux and other systems:
/opt/install4j13/bin/install4jc
If the install4j is installed in a different location you can specify location of the compiler using the environment
variable INSTALL4JC_FILE, system property INSTALL4JC_FILE, or SBT setting install4jcFile.
The system property takes precedence over the environment variable. For multi-platform builds it is
preferred to use the environment variable INSTALL4JC_FILE.
You can set the system property when starting SBT using -D option, for instance:
$ sbt -DINSTALL4JC_FILE="C:/Program Files/install4j13/bin/install4jc.exe"In sbt 2, sbt command connects to an sbt server running in the background, by default. The server keeps the system
properties and environment variables it was started with. After changing INSTALL4JC_FILE stop the server with
sbt shutdown, or run sbt in the foreground, without the background server, using sbt --server.
ScalaFX Ensemble is an example of an application that is making use of sbt-install4j to create an installer with install4j
sbt-install4j does not add the install4j API to the classpath.
If you use the install4j API in your application,
add i4jruntime.jar from the resource directory of the install4j installation yourself.
The installer provides it at runtime, so exclude it from copying to the installer:
// sbt 1
Compile / unmanagedJars += install4jHomeDir.value / "resource" / "i4jruntime.jar"
// sbt 2
Compile / unmanagedJars += Attributed.blank[xsbti.HashedVirtualFileRef](
fileConverter.value.toVirtualFile((install4jHomeDir.value / "resource" / "i4jruntime.jar").toPath)
)
install4jCopyDependedJarsExclusions += """i4jruntime\.jar"""If your install4j is not in the default location, set environment variable INSTALL4J_HOME to its installation
directory.
For instance, sbt-install4j uses install4j 13 as default, if you have install4j 12 installed, on Windows
that would typically be C:\Program Files\install4j12.
To see debugging information set SBT logging level to debug:
sbt> debugLook in the log for lines prefixed with [debug] [sbt-install4j].
sbt-install4j is licensed under Apache 2.0 license.
