For an example on how to use the plugin, see the Spaghetti Gradle example here. If you want to work with one of the supported languages, it's better to use the Spaghetti plugin through its language-specific descendants:
- the Spaghetti TypeScript plugin, or
- the Spaghetti Haxe plugin.
Gradle 2.0 or newer is required to use the plugins.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "com.prezi.spaghetti:gradle-spaghetti-plugin:<version>"
}
}
apply plugin: "spaghetti"
For available version numbers, please check the list of Spaghetti releases.
When applied to a project, the plugin configures a number of things:
- Creates the
modules
configuration -- the main configuration to publish module bundles to - Creates the
modulesObf
configuration to publish obfuscated module bundles to - Adds the
spaghetti
extension to the build - Adds a
GenerateHeaders
task (see below) that looks for definitions insrc/main/spaghetti
When using either the Spaghetti Haxe plugin or the Spaghetti TypeScript plugin, generated code will automatically be included in the compilation of your code, and a BundleModule and an ObfuscateModule task is automatically created. The bundled and obfuscated ZIPs are automatically added to the artifacts of the modules
and modulesObf
configurations, respectively.
spaghetti {
// Pre-configure all Spaghetti tasks to use this language
language <language>
// Use this configuration to look for dependent modules and to publish bundles
configuration <configuration>
// Use this configuration to publish obfuscated bundles
obfuscatedConfiguration <configuration>
}
task generateHeaders(type: com.prezi.spaghetti.gradle.GenerateHeaders) {
// The Spaghetti definition file
definition <file>
// The language to generate headers in
language <language>
// Dependent module bundles
// Accepts all parameters as project.files()
dependentModules <files...>
// The location to generate headers into
outputDirectory <directory>
}
task bundleModule(type: com.prezi.spaghetti.gradle.BundleModule) {
// The Spaghetti definition file
definition <file>
// The language of the module's implementation
language <language>
// The compiled JavaScript code of the module
inputFile <file>
// Dependent module bundles
// Accepts all parameters as project.files()
dependentModules <files...>
// The location to create the bundle in
outputDirectory <directory>
}
The ObfuscateModule
task takes the same properties as BundleModule
, and adds some more:
task obfuscateModule(type: com.prezi.spaghetti.gradle.ObfuscateModule) {
// Extern definition files for Closure (see below)
closureExterns <files>
// Additional symbols to protect during Closure compilation
additionalSymbols <symbols>
// Working directory for Closure compiler
workDir <directory>
}
Read more here about why and how externs can be useful.
task packageApplication(type: com.prezi.spaghetti.gradle.PackageApplication) {
// Dependent module bundles
// Accepts all parameters as project.files()
dependentModules <files...>
// Name of the main module of the application
mainModule <name>
// Whether or not to actually call mainModule.main()
execute <true|false>
// The name of the application (executable name is applicationName + '.js')
applicationName <name>
// The type of the packaging (see below)
type <packaging>
// The location to create the bundle in
outputDirectory <directory>
}
Available packaging types are (case-insensitive):
node
orcommonjs
for CommonJS/NodeJS compatible executableamd
orrequirejs
for AMD/RequireJS compatible executable