Skip to content


Subversion checkout URL

You can clone with
Download ZIP
TypeScript Gradle Plugin, integrates the TypeScript compiler into a Gradle build
Groovy TypeScript Java HTML

TypeScript Gradle Plugin

This plugin makes it easy to build TypeScript projects using Gradle. Among other things, the plugin provides a task to run the TypeScript compiler.


Several example projects can be found in /examples.


You need to have installed node.js and installed the typescript node module:

npm install -g typescript

Alternatively on windows you can install the Typescript SDK and configure the compilerExecutable config option to tsc - see Available configuration options.


This will guide you through the steps needed to set up typescript-gradle-plugin for a TypeScript application project using Maven/Gradle standard layout.

Plugin dependency

As this is not a core Gradle plugin, you have to ensure, that Gradle knows how to get the plugin. Do do this, add the following lines to your build.gradle:

buildscript {
    repositories {
        maven {
            url ''
    dependencies {
        classpath 'de.richsource.gradle.plugins:typescript-gradle-plugin:1.5'

Next, apply the plugin.

apply plugin: "typescript"

Configuring the TypeScript compile task

You can configure the TypeScript compile task as shown below:

compileTypeScript {
    sourcemap = true
    // additional configuration options

Run the TypeScript compiler

gradle compileTypeScript

Available configuration options

Here is a list of the available configuration options of the compileTypeScript task:

  • source - (File) directories to compile, defaults to src/main/ts
  • outputDir - (File) the output directory, defaults to buildDir/ts
  • out - (File) Concatenate and emit output to single file, e.g. file("${buildDir}/js/out.js")
  • module - (de.richsource.gradle.plugins.typescript.Module) Specify module code generation (AMD, COMMONJS, SYSTEM, UMD)
  • target - (de.richsource.gradle.plugins.typescript.Target) Specify ECMAScript target version (ES3, ES5 or ES6)
  • declaration - (boolean) Generates corresponding .d.ts file
  • noImplicitAny - (boolean) Warn on expressions and declarations with an implied 'any' type
  • noResolve - (boolean) Skip resolution and preprocessing
  • removeComments - (boolean) Do not emit comments to output
  • sourcemap - (boolean) Generates corresponding .map file
  • sourceRoot - (File) Specifies the location where debugger should locate TypeScript files instead of source locations
  • codepage - (Integer) Specify the codepage to use when opening source files
  • mapRoot - (File) Specifies the location where debugger should locate map files instead of generated locations
  • compilerExecutable - (String) The tsc compiler executable to use. Defaults to cmd /c tsc.cmd on windows and tsc on other systems.
  • noEmitOnError - (boolean) Do not emit outputs if any type checking errors were reported
  • noEmit - (boolean) Do not emit outputs
  • experimentalDecorators - (boolean) Enables experimental support for ES7 decorators
  • newline - (de.richsource.gradle.plugins.typescript.Newline) Specifies the end of line sequence to be used when emitting files (CRLF or LF)
  • preserveConstEnums - (boolean) Do not erase const enum declarations in generated code
  • projectFileDir - (File) Compile the project in the given directory where a tsconfig.json file is present. File specified with the source option will be ignore, but you should still explicitely configure the source files as this will make the Gradle UP-TO-DATE check work.
  • rootDir - (File) Specifies the root directory of input files. Use to control the output directory structure with outDir.
  • suppressImplicitAnyIndexErrors - (boolean) Suppress noImplicitAny errors for indexing objects lacking index signatures
  • noEmitHelpers - (boolean) Do not emit helpers like __extends
  • inlineSourceMap - (boolean) Causes source map files to be written inline in the generated .js files instead of in a independent file
  • inlineSources - (boolean) Allows for additionally inlining the source .ts file into the .js file when used in combination with inlineSourceMap

Integrating the compiled files into a WAR file (for Java Webapps)

If you are integrating TypeScript into a Java web application, you can easily integrate the compiled files into the WAR file. All you have to do is to configure the war task to pick up the compiled files. Whenever you call the war task, the TypeScript compiler will compile your TypeScript files first. In the example below, the compiled files will be put into the js directory in the WAR file.

apply plugin: "war"

war {
        into("js") {
            from compileTypeScript.outputs

Configuring multiple source directories

You can configure the TypeScript compile task to use multiple source directories as shown below:

compileTypeScript {
    source = [file("src/main/ts"), file("src/main/additionalts")]
Something went wrong with that request. Please try again.