1# [Google Closure Compiler](https://developers.google.com/closure/compiler/)
2
3The [Closure Compiler](https://developers.google.com/closure/compiler/) is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls.
4
5## Getting Started
6 * [Download the latest version](http://dl.google.com/closure-compiler/compiler-latest.zip)
7 * See the [Google Developers Site](https://developers.google.com/closure/compiler/docs/gettingstarted_app) for documentation including instructions for running the compiler from the command line.
8
9## Options for Getting Help
101. Post in the [Closure Compiler Discuss Group] (https://groups.google.com/forum/#!forum/closure-compiler-discuss)
112. Ask a question on [Stack Overflow](http://stackoverflow.com/questions/tagged/google-closure-compiler)
123. Consult the [FAQ](https://github.com/google/closure-compiler/wiki/FAQ)
13
14## Building it Yourself
15
16Note: The Closure Compiler requires [Java 7 or higher](http://www.java.com/).
17
18### Using [Ant](http://ant.apache.org/)
19
201. Download the [Ant build tool](http://ant.apache.org/bindownload.cgi).
21
222. At the root of the source tree, there is an Ant file named ```build.xml```.
23   To use it, navigate to the same directory and type the command
24
25    ```
26    ant jar
27    ```
28
29    This will produce a jar file called ```build/compiler.jar```.
30
31### Using [Eclipse](http://www.eclipse.org/)
32
331. Download and open the [Eclipse IDE](http://www.eclipse.org/).
342. Navigate to ```File > New > Project ...``` and create a Java Projet. Give
35   the project a name.
363. Select ```Create project from existing source``` and choose the root of the
37   checked-out source tree as the existing directory.
383. Navigate to the ```build.xml``` file. You will see all the build rules in
39   the Outline pane. Run the ```jar``` rule to build the compiler in
40   ```build/compiler.jar```.
41
42## Running
43
44On the command line, type
45
46```
47java -jar compiler.jar
48```
49
50This starts the compiler in interactive mode. Type
51
52```javascript
53var x = 17 + 25;
54```
55
56then hit "Enter", then hit "Ctrl-Z" (on Windows) or "Ctrl-D" (on Mac or Linux)
57and "Enter" again. The Compiler will respond:
58
59```javascript
60var x=42;
61```
62
63The Closure Compiler has many options for reading input from a file, writing
64output to a file, checking your code, and running optimizations. To learn more,
65type
66
67```
68java -jar compiler.jar --help
69```
70
71More detailed information about running the Closure Compiler is available in the
72[documentation](http://code.google.com/closure/compiler/docs/gettingstarted_app.html).
73
74## Compiling Multiple Scripts
75
76If you have multiple scripts, you should compile them all together with one
77compile command.
78
79```bash
80java -jar compiler.jar --js_output_file=out.js in1.js in2.js in3.js ...
81```
82
83You can also use minimatch-style globs.
84
85```bash
86# Recursively include all js files in subdirs
87java -jar compiler.jar --js_output_file=out.js 'src/**.js'
88
89# Recursively include all js files in subdirs, exclusing test files.
90# Use single-quotes, so that bash doesn't try to expand the '!'
91java -jar compiler.jar --js_output_file=out.js 'src/**.js' '!**_test.js'
92```
93
94The Closure Compiler will concatenate the files in the order they're passed at
95the command line.
96
97If you're using globs or many files, you may start to run into
98problems with managing dependencies between scripts. In this case, you should
99use the [Closure Library](https://developers.google.com/closure/library/). It
100contains functions for enforcing dependencies between scripts, and Closure Compiler
101will re-order the inputs automatically.
102
103## How to Contribute
104### Reporting a bug
1051. First make sure that it is really a bug and not simply the way that Closure Compiler works (especially true for ADVANCED_OPTIMIZATIONS).
106 * Check the [official documentation](https://developers.google.com/closure/compiler/)
107 * Consult the [FAQ](https://github.com/google/closure-compiler/wiki/FAQ)
108 * Search on [Stack Overflow](http://stackoverflow.com/questions/tagged/google-closure-compiler) and in the [Closure Compiler Discuss Group](https://groups.google.com/forum/#!forum/closure-compiler-discuss)
1092. If you still think you have found a bug, make sure someone hasn't already reported it. See the list of [known issues](https://github.com/google/closure-compiler/issues).
1103. If it hasn't been reported yet, post a new issue. Make sure to add enough detail so that the bug can be recreated. The smaller the reproduction code, the better.
111
112### Suggesting a Feature
1131. Consult the [FAQ](https://github.com/google/closure-compiler/wiki/FAQ) to make sure that the behaviour you would like isn't specifically excluded (such as string inlining).
1142. Make sure someone hasn't requested the same thing. See the list of [known issues](https://github.com/google/closure-compiler/issues).
1153. Read up on [what type of feature requests are accepted](https://github.com/google/closure-compiler/wiki/FAQ#how-do-i-submit-a-feature-request-for-a-new-type-of-optimization).
1164. Submit your reqest as an issue.
117
118### Submitting patches
1191. All contributors must sign a contributor license agreement. See the [CONTRIBUTORS](https://raw.githubusercontent.com/google/closure-compiler/master/CONTRIBUTORS) file for details.
1202. To make sure your changes are of the type that will be accepted, ask about your patch on the [Closure Compiler Discuss Group](https://groups.google.com/forum/#!forum/closure-compiler-discuss)
1213. Fork the repository.
1224. Make your changes.
1235. Submit a pull request for your changes. A project developer will review your work and then merge your request into the project.
124
125## Closure Compiler License
126
127Copyright 2009 The Closure Compiler Authors.
128
129Licensed under the Apache License, Version 2.0 (the "License");
130you may not use this file except in compliance with the License.
131You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
132
133Unless required by applicable law or agreed to in writing, software
134distributed under the License is distributed on an "AS IS" BASIS,
135WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136See the License for the specific language governing permissions and
137limitations under the License.
138
139## Dependency Licenses
140
141### Rhino
142
143Two copies of Rhino exist in this repository:
144
145<table>
146  <tr>
147    <td>Code Path</td>
148    <td><code>lib/rhino</code></td>
149  </tr>
150
151  <tr>
152    <td>URL</td>
153    <td>http://www.mozilla.org/rhino</td>
154  </tr>
155  
156  <tr>
157    <td>Version</td>
158    <td>Trunk</td>
159  </tr>
160  
161  <tr>
162    <td>License</td>
163    <td>Netscape Public License and MPL / GPL dual license</td>
164  </tr>
165  
166  <tr>
167    <td>Description</td>
168    <td>Mozilla Rhino is an implementation of JavaScript for the JVM.</td>
169  </tr>
170  
171  <tr>
172    <td>Local Modifications</td>
173    <td>Minor changes to parsing JSDoc that usually get pushed
174  up-stream to Rhino trunk.</td>
175  </tr>
176</table>
177
178<table>
179  <tr>
180    <td>Code Path</td>
181    <td>
182      <code>src/com/google/javascript/rhino</code>, <code>test/com/google/javascript/rhino</code>
183    </td>
184  </tr>
185
186  <tr>
187    <td>URL</td>
188    <td>http://www.mozilla.org/rhino</td>
189  </tr>
190  
191  <tr>
192    <td>Version</td>
193    <td>1.5R3, with heavy modifications</td>
194  </tr>
195  
196  <tr>
197    <td>License</td>
198    <td>Netscape Public License and MPL / GPL dual license</td>
199  </tr>
200  
201  <tr>
202    <td>Description</td>
203    <td>A partial copy of Mozilla Rhino. Mozilla Rhino is an
204implementation of JavaScript for the JVM.  The JavaScript parser and
205the parse tree data structures were extracted and modified
206significantly for use by Google's JavaScript compiler.</td>
207  </tr>
208  
209  <tr>
210    <td>Local Modifications</td>
211    <td>The packages have been renamespaced. All code not
212relevant to parsing has been removed. A JsDoc parser and static typing
213system have been added.</td>
214  </tr>
215</table>
216
217### Args4j
218
219<table>
220  <tr>
221    <td>Code Path</td>
222    <td><code>lib/args4j.jar</code></td>
223  </tr>
224
225  <tr>
226    <td>URL</td>
227    <td>https://args4j.dev.java.net/</td>
228  </tr>
229  
230  <tr>
231    <td>Version</td>
232    <td>2.0.26</td>
233  </tr>
234  
235  <tr>
236    <td>License</td>
237    <td>MIT</td>
238  </tr>
239  
240  <tr>
241    <td>Description</td>
242    <td>args4j is a small Java class library that makes it easy to parse command line
243options/arguments in your CUI application.</td>
244  </tr>
245  
246  <tr>
247    <td>Local Modifications</td>
248    <td>None</td>
249  </tr>
250</table>
251
252### Guava Libraries
253
254<table>
255  <tr>
256    <td>Code Path</td>
257    <td><code>lib/guava.jar</code></td>
258  </tr>
259
260  <tr>
261    <td>URL</td>
262    <td>http://code.google.com/p/guava-libraries/</td>
263  </tr>
264  
265  <tr>
266    <td>Version</td>
267    <td>17.0</td>
268  </tr>
269  
270  <tr>
271    <td>License</td>
272    <td>Apache License 2.0</td>
273  </tr>
274  
275  <tr>
276    <td>Description</td>
277    <td>Google's core Java libraries.</td>
278  </tr>
279  
280  <tr>
281    <td>Local Modifications</td>
282    <td>None</td>
283  </tr>
284</table>
285
286### JSR 305
287
288<table>
289  <tr>
290    <td>Code Path</td>
291    <td><code>lib/jsr305.jar</code></td>
292  </tr>
293
294  <tr>
295    <td>URL</td>
296    <td>http://code.google.com/p/jsr-305/</td>
297  </tr>
298  
299  <tr>
300    <td>Version</td>
301    <td>svn revision 47</td>
302  </tr>
303  
304  <tr>
305    <td>License</td>
306    <td>BSD License</td>
307  </tr>
308  
309  <tr>
310    <td>Description</td>
311    <td>Annotations for software defect detection.</td>
312  </tr>
313  
314  <tr>
315    <td>Local Modifications</td>
316    <td>None</td>
317  </tr>
318</table>
319
320### Jar Jar Links
321
322<table>
323  <tr>
324    <td>Code Path</td>
325    <td><code>lib/jarjar.jar</code></td>
326  </tr>
327
328  <tr>
329    <td>URL</td>
330    <td>http://jarjar.googlecode.com/</td>
331  </tr>
332  
333  <tr>
334    <td>Version</td>
335    <td>1.1</td>
336  </tr>
337  
338  <tr>
339    <td>License</td>
340    <td>Apache License 2.0</td>
341  </tr>
342  
343  <tr>
344    <td>Description</td>
345    <td>A utility for repackaging Java libraries.</td>
346  </tr>
347  
348  <tr>
349    <td>Local Modifications</td>
350    <td>None</td>
351  </tr>
352</table>
353
354### JUnit
355
356<table>
357  <tr>
358    <td>Code Path</td>
359    <td><code>lib/junit.jar</code></td>
360  </tr>
361
362  <tr>
363    <td>URL</td>
364    <td>http://sourceforge.net/projects/junit/</td>
365  </tr>
366  
367  <tr>
368    <td>Version</td>
369    <td>4.11</td>
370  </tr>
371  
372  <tr>
373    <td>License</td>
374    <td>Common Public License 1.0</td>
375  </tr>
376  
377  <tr>
378    <td>Description</td>
379    <td>A framework for writing and running automated tests in Java.</td>
380  </tr>
381  
382  <tr>
383    <td>Local Modifications</td>
384    <td>None</td>
385  </tr>
386</table>
387
388### Protocol Buffers
389
390<table>
391  <tr>
392    <td>Code Path</td>
393    <td><code>lib/protobuf-java.jar</code></td>
394  </tr>
395
396  <tr>
397    <td>URL</td>
398    <td>http://code.google.com/p/protobuf/</td>
399  </tr>
400  
401  <tr>
402    <td>Version</td>
403    <td>2.5.0</td>
404  </tr>
405  
406  <tr>
407    <td>License</td>
408    <td>New BSD License</td>
409  </tr>
410  
411  <tr>
412    <td>Description</td>
413    <td>Supporting libraries for protocol buffers,
414an encoding of structured data.</td>
415  </tr>
416  
417  <tr>
418    <td>Local Modifications</td>
419    <td>None</td>
420  </tr>
421</table>
422
423### Ant
424
425<table>
426  <tr>
427    <td>Code Path</td>
428    <td>
429      <code>lib/ant.jar</code>, <code>lib/ant-launcher.jar</code>
430    </td>
431  </tr>
432
433  <tr>
434    <td>URL</td>
435    <td>http://ant.apache.org/bindownload.cgi</td>
436  </tr>
437  
438  <tr>
439    <td>Version</td>
440    <td>1.8.1</td>
441  </tr>
442  
443  <tr>
444    <td>License</td>
445    <td>Apache License 2.0</td>
446  </tr>
447  
448  <tr>
449    <td>Description</td>
450    <td>Ant is a Java based build tool. In theory it is kind of like "make"
451without make's wrinkles and with the full portability of pure java code.</td>
452  </tr>
453  
454  <tr>
455    <td>Local Modifications</td>
456    <td>None</td>
457  </tr>
458</table>
459
460### JSON
461
462<table>
463  <tr>
464    <td>Code Path</td>
465    <td><code>lib/json.jar</code></td>
466  </tr>
467
468  <tr>
469    <td>URL</td>
470    <td>http://json.org/java/index.html</td>
471  </tr>
472  
473  <tr>
474    <td>Version</td>
475    <td>JSON version 20090211</td>
476  </tr>
477  
478  <tr>
479    <td>License</td>
480    <td>MIT license</td>
481  </tr>
482  
483  <tr>
484    <td>Description</td>
485    <td>JSON is a set of java files for use in transmitting data in JSON format.</td>
486  </tr>
487  
488  <tr>
489    <td>Local Modifications</td>
490    <td>None</td>
491  </tr>
492</table>
493
494### Mockito
495
496<table>
497  <tr>
498    <td>Code Path</td>
499    <td><code>lib/mockito-core.jar</code></td>
500  </tr>
501
502  <tr>
503    <td>URL</td>
504    <td>https://code.google.com/p/mockito</td>
505  </tr>
506  
507  <tr>
508    <td>Version</td>
509    <td>1.9.5</td>
510  </tr>
511  
512  <tr>
513    <td>License</td>
514    <td>MIT license</td>
515  </tr>
516  
517  <tr>
518    <td>Description</td>
519    <td>Mockito is an open source testing framework for Java. The framework allows the
520creation of Test Double objects (called "Mock Objects") in automated unit tests
521for the purpose of Test-driven Development (TDD) or Behavior Driven Development
522(BDD).</td>
523  </tr>
524  
525  <tr>
526    <td>Local Modifications</td>
527    <td>None</td>
528  </tr>
529</table>
530
531### Objenesis
532
533<table>
534  <tr>
535    <td>Code Path</td>
536    <td><code>lib/objenesis.jar</code></td>
537  </tr>
538
539  <tr>
540    <td>URL</td>
541    <td>http://objenesis.org</td>
542  </tr>
543  
544  <tr>
545    <td>Version</td>
546    <td>1.2</td>
547  </tr>
548  
549  <tr>
550    <td>License</td>
551    <td>Apache 2.0 license</td>
552  </tr>
553  
554  <tr>
555    <td>Description</td>
556    <td>Depended by lib/mockito-core.jar, not used directly.</td>
557  </tr>
558  
559  <tr>
560    <td>Local Modifications</td>
561    <td>None</td>
562  </tr>
563</table>
564